How to refetch(refresh) next-auth session manually on the client side?
Let's say the app has two unique models user and profile, both are in a one to one relation. User object will have a field named
profileId
which can be a string
or null
depending on whether the user object has a profile linked to it.
After a successful sign in we get the user session object back which has profileId === null. Then we force the user to create a profile if they want to make use of all functionalities of the app. So, the user creates a profile which gets linked to their user object in the database.
Now session.user.profileId === "somethingId". How do I refresh the session to update this change on client side without any page reloads and stuff? Like doing it the react way, refetch the sesion, set the session state to the refetched value.5 Replies
on their docs they suggested this https://next-auth.js.org/getting-started/client#options
Client API | NextAuth.js
The NextAuth.js client library makes it easy to interact with sessions from React applications.
but calling
getSession
doesn't workUnknown User•3y ago
Message Not Public
Sign In & Join Server To View
I am returning the session data. The updated session is fetched when I run
getSession()
. But the session state stored by next auth's session provider that wraps the app doesn't update. It only updates when I refresh the whole page(app), or on a windowRefocusEvent
. There's no programmatic way listed on next auth's docs to update the session manually.
updated session is returned in the network tab, but the session state doesn't updateUnknown User•3y ago
Message Not Public
Sign In & Join Server To View