-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UserManager.events().unload()
event is triggered too early on UserManager.signoutRedirect()
#1341
Comments
…s actually signed out Prevents race conditions with event handlers which react to this unload event and expect the user to be signed out already. Fixes authts#1341
I see your point, makes sense, thanks for taking care... |
…s actually signed out Prevents race conditions with event handlers which react to this unload event and expect the user to be signed out already. Fixes authts#1341
If you would not react with redirect, you would not have that issue at all. Why do you react with a redirect to login page with |
As far I know I need to react to the user unload event also for other reasons like session timeout which might lead to a user unload event. In all these cases I want to show the login page to the user as the actual application is only intended for users which are logged in. |
@pamapa Actually our application does not depend directly on that event, but it depends on reacting to How do you suggest to react to a change of the |
Locally he is no longer as we have remove the user object locally, but on the IDP the user still has for a very short time a valid session. But that session is now useless, as the local tokens are gone. Can you post the code of what you are doing in the !isAuthenticated case? |
@pamapa It looks like this: const { isAuthenticated, isLoading, signinRedirect } = useAuth();
const login = () =>
signinRedirect({
scope: 'openid',
redirect_uri: myRedirectUri
});
// automatically sign-in
React.useEffect(() => {
if (!isAuthenticated && !isLoading) {
void login();
}
}, [isAuthenticated, isLoading]); (I removed a little clutter, but this is generally the logic.) The same code is also triggered when the user opens the page but is not yet logged in. |
Have you see https://github.com/authts/react-oidc-context?tab=readme-ov-file#automatic-sign-in, there is more to add... |
@pamapa I think essentially we are doing exactly that what is suggested in that section. Do you see any major differences? |
In your code it do not see checking for active navigator: const auth = useAuth();
const [hasTriedSignin, setHasTriedSignin] = React.useState(false);
// automatically sign-in
React.useEffect(() => {
if (!hasAuthParams() &&
!auth.isAuthenticated && !auth.activeNavigator && !auth.isLoading &&
!hasTriedSignin
) {
auth.signinRedirect();
setHasTriedSignin(true);
}
}, [auth, hasTriedSignin]);
``` |
Yes sorry. That activeNavigator was there in the actual code, but I removed it here as I thought it was not important for this case. Regarding retry preventing: I am not sure why it would make a difference as the issue is that |
fyi: For us using |
Good to hear, i just temporary added |
For us this bug started to happen when we started to manually pass UserManager instance to the react-oidc-context's AuthProvider and using the same instance to signoutRedirect in the onClick handler (before that since the onClick triggered a redux action we had to create a new instance of user manager with same config passed to AuthProvider - and signoutRedirect from there. It seems like it did work because a different UserManager instance was removing the user and not the one used in the react component (i'm guessing) We were using roughly the same code as provided by react-oidc-context readme We currently implemented a workaround that checks if we started the signout or not, but i would've expected for
|
…s actually signed out Prevents race conditions with event handlers which react to this unload event and expect the user to be signed out already. Fixes authts#1341
We observed the
UserManager.events().unload()
event was fired too early, before the user was actually signed out. Our application reacted with a redirect to the login page to this event, but as there was the possibilty of a race condition between login redirect and actual signout, the signout might not yet have happened and therefore resulted in an unsuccessful signout.The problematic code is located in
UserManager._signoutStart()
, which is called fromUserManager.signoutRedirect()
:oidc-client-ts/src/UserManager.ts
Lines 623 to 624 in 4a8d6d9
I would expect this code instead to be located in
UserManager._signoutEnd()
where it should be guaranteed that the user was successfully signed out.I will create a PR to fix this issue.
The text was updated successfully, but these errors were encountered: