File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,7 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
141141 }
142142 ( async ( ) => {
143143 setInitialized ( await AuthClient . init ( config ) ) ;
144+ checkIsAuthenticated ( ) ;
144145 } ) ( ) ;
145146
146147 } , [ config ] ) ;
@@ -238,6 +239,35 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
238239
239240 } , [ config ] ) ;
240241
242+ /**
243+ * Check if the user is authenticated and update the state.isAuthenticated value.
244+ */
245+ const checkIsAuthenticated = async ( ) => {
246+ const isAuthenticatedState = await AuthClient . isAuthenticated ( ) ;
247+
248+ if ( isAuthenticatedState ) {
249+ const response = await AuthClient . getBasicUserInfo ( ) ;
250+
251+ if ( response ) {
252+ const stateToUpdate = {
253+ allowedScopes : response . allowedScopes ,
254+ displayName : response . displayName ,
255+ email : response . email ,
256+ isAuthenticated : true ,
257+ isLoading : false ,
258+ isSigningOut : false ,
259+ sub : response . sub ,
260+ username : response . username
261+ } ;
262+
263+ AuthClient . updateState ( stateToUpdate ) ;
264+ dispatch ( { ...state , ...stateToUpdate } ) ;
265+
266+ return ;
267+ }
268+ }
269+ } ;
270+
241271 /**
242272 * Render state and special case actions
243273 */
You can’t perform that action at this time.
0 commit comments