-
Notifications
You must be signed in to change notification settings - Fork 8
/
FrontendPlatformWrapper.jsx
82 lines (70 loc) · 2.06 KB
/
FrontendPlatformWrapper.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React, { useEffect, useState } from 'react';
import 'regenerator-runtime/runtime';
import { messages } from '@edx/frontend-component-footer-edx';
import { AppProvider } from '@edx/frontend-platform/react';
import {
configure as configureAuth,
AxiosJwtAuthService,
getAuthenticatedHttpClient,
ensureAuthenticatedUser,
hydrateAuthenticatedUser,
getAuthenticatedUser,
} from '@edx/frontend-platform/auth';
import { mergeConfig, getConfig } from '@edx/frontend-platform/config';
import {
configure as configureLogging,
getLoggingService,
NewRelicLoggingService,
} from '@edx/frontend-platform/logging';
import {
configure as configureAnalytics,
SegmentAnalyticsService,
identifyAuthenticatedUser,
} from '@edx/frontend-platform/analytics';
import {
configure as configureI18n,
} from '@edx/frontend-platform/i18n';
import store from './src/store';
// eslint-disable-next-line react/display-name,react/prop-types
export default function ({ children }) {
const [ready, setReady] = useState(false);
useEffect(() => {
if (process.env.IDP_SLUG) {
mergeConfig({
LOGIN_URL: `${process.env.LMS_BASE_URL}/auth/idp_redirect/${process.env.IDP_SLUG}`,
});
}
configureLogging(NewRelicLoggingService, {
config: getConfig(),
});
configureAuth(AxiosJwtAuthService, {
loggingService: getLoggingService(),
config: getConfig(),
});
// Analytics
configureAnalytics(SegmentAnalyticsService, {
config: getConfig(),
loggingService: getLoggingService(),
httpClient: getAuthenticatedHttpClient(),
});
// Internationalization
configureI18n({
messages,
config: getConfig(),
loggingService: getLoggingService(),
});
ensureAuthenticatedUser().then(() => {
hydrateAuthenticatedUser().then(() => {
const authUser = getAuthenticatedUser();
identifyAuthenticatedUser(authUser.userId);
setReady(true);
});
});
}, []);
if (!ready) {
return null;
}
return (
<AppProvider store={store}>{children}</AppProvider>
);
}