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
Hi, I am a newbie with next-auth. my app still uses a frontend and backend separation, and I'm using CredentailProvider for login to obtain an access token from the backend server. when I fetch data from the API on the page and the API responds with a 401, I want to log out automatically. I noticed that signOut() is a client-side function, so I can't call signOut().
my sample code:
importauthfrom"@/lib/auth";exportdefaultasyncfunctionPage(){constsession=awaitauth();consttoken=session?.accessToken;constdata=awaitgetData({token: token||"",});if(data.status===401){// I want to logout herereturn<p>Error: {data.error}</p>;}return(<>{data.result}<>
);
}
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I am a newbie with next-auth. my app still uses a frontend and backend separation, and I'm using CredentailProvider for login to obtain an access token from the backend server. when I fetch data from the API on the page and the API responds with a 401, I want to log out automatically. I noticed that
signOut()
is a client-side function, so I can't callsignOut()
.my sample code:
I am using the Next-Auth v5
Beta Was this translation helpful? Give feedback.
All reactions