You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello ! I'm using Next-Auth with a FaunaDB Database & a custom adapter.
I'm not using JWT, my aim is to store an accessToken from the adapter on the session object to be able to call the DB from the user perspective.
Basically, the Adapter creates the accessToken on createSession & updateSession (if session needs to be updated, depending on maxAge).
callbacks: {asyncsession(session, ...rest){// Session here is always the old (un-updated one)constclient=newClient({secret: session.accessToken});// DB Clienttry{return{
...session,user: awaitclient.query(getUser({})),// Getting more user info};}catch(err){returnsession;}},}
The accessToken is updated when the session is, so the access is not expired.
The issue is that the session inside the callbacks options is always getting the first session, not the updated one.
So the updated accessToken is not used directly, so we get a 401 query on the DB (accessToken is expired).
What I don't understand, is that by using the debug option, I can see those steps :
Adapter::getSession called
Adapter::updateSession called, can stop the return, or update session
Session Callback is called, but gets the old session
How can the callback get the updated session instead ?
Should I move the update of the accessToken of the session inside the the session callback, instead of inside the Adapter (updateSession) ?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello ! I'm using Next-Auth with a FaunaDB Database & a custom adapter.
I'm not using JWT, my aim is to store an accessToken from the adapter on the session object to be able to call the DB from the user perspective.
Basically, the Adapter creates the
accessToken
oncreateSession
&updateSession
(if session needs to be updated, depending on maxAge).The accessToken is updated when the session is, so the access is not expired.
The issue is that the session inside the callbacks options is always getting the first session, not the updated one.
So the updated accessToken is not used directly, so we get a 401 query on the DB (accessToken is expired).
What I don't understand, is that by using the debug option, I can see those steps :
Adapter::getSession
calledAdapter::updateSession
called, can stop the return, or update sessionHow can the callback get the updated session instead ?
Should I move the update of the accessToken of the session inside the the session callback, instead of inside the Adapter (updateSession) ?
Feels like this should be handled by the Adapter.
Thank you !
Beta Was this translation helpful? Give feedback.
All reactions