Skip to content

Commit 1716e35

Browse files
Fix state refresh bug in v1
1 parent 71cd0e3 commit 1716e35

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lib/src/authenticate.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff 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
*/

0 commit comments

Comments
 (0)