-
Notifications
You must be signed in to change notification settings - Fork 149
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
useOidcUser briefly returning null on page navigation refresh during authenticated session [NextJs] #1353
Comments
Hi @kramer99 thank you for your issue and feedback. |
version v7.22.4-alpha.1425 should work better @kramer99 :) |
Confirmed, fix looks good on my side. Thanks for the quick work @guillaume-chervet ! |
Sorry @guillaume-chervet - it looks like it was only a partial fix. Behaviour is correct during page navigation and refresh, but there is still a problem when receiving the callback after authentication. If you add |
Hi @kramer99, I fail to reproduce it. Do you have way to reproduce it on the react oidc demo? |
You can clone this: https://github.com/kramer99/oidc-test ...update |
thank you @kramer99 , i can reproduce it with your demo :) |
hi @kramer99 , I have added preload_user_info: true ine the configuration and it works on my side :) |
I didn't notice a difference with or without the You cleared localStorage immediately before you tested successfully? |
@guillaume-chervet I'm experiencing similar issue where after login, the Following is the configuration: export const configurationIdentityServerWithoutServiceWorker = {
client_id: 'interactive.public.short',
redirect_uri: window.location.origin + '/callback',
silent_redirect_uri: window.location.origin + '/silent-callback',
scope: IDENTITY_SERVER_SCOPE,
authority: 'http://localhost:8080',
// authority_time_cache_wellknowurl_in_second: 60* 60,
refresh_time_before_tokens_expiration_in_second: 40,
storage: localStorage,
//
preload_user_info: true
}; Version: 7.22.4 |
Hi @attiqeurrehman thank you for your feedback again. I will investigate it after my holiday near the 13 may. Thank to all your details I think it will be easy to reproduce and debug. |
@guillaume-chervet any update on this? |
@attiqeurrehman @kramer99 I just push the fix. Sorry, I had big holdidays time :) |
@guillaume-chervet no worries, hope you had a good time. |
@guillaume-chervet fix looks good on my side. I'll close this unless @attiqeurrehman objects. |
Works like a charm. You can close this. Thanks a lot! |
Issue and Steps to Reproduce
Create a starter NextJs app (choose "no" to App router, "yes" to
src/
):Modify
src/pages/index.tsx
to:Modify
src/pages/_app.tsx
:Add a callback route
src/pages/ibor/callback/index.tsx
:Versions
7.22.3
(I also tried the alpha version mentioned here: #1090, with the new config option, but had no success there)
Screenshots
Expected
useOidcUser
always returns the user object when user is authenticated (and we're not in an SSR context)Actual
After authenticating, you'll see:
...and in the console:
I had at first assumed the reason would be that
useOidcUser
was getting called during Server Side Rendering... but as you can see, that's not the cause (note theisBrowser
check). So local / session storage should be available at that time.If you refresh the page, or navigate to another route, you'll see the same thing.
The reason this matters is that if you're taking, say, the name or email address of the logged in user and displaying them in a header, they will flicker and disappear before reappearing whenever the user navigates / refreshes. There are workarounds (you can cache it in some state somewhere) - but that's obviously not ideal.
Additional Details
The text was updated successfully, but these errors were encountered: