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 having an issue with cookies, i have refresh and access token both sent as cookies.
However when i try to login in using credentials, only the access token is persisted and refresh_token somehow got removed:
/* eslint-disable @typescript-eslint/ban-ts-comment *//* eslint-disable no-param-reassign */importNextAuth,{DefaultSession,DefaultUser}from'next-auth';importCredentialsProviderfrom'next-auth/providers/credentials';declare module 'next-auth'{interfaceSession{user: {id: number;email: string;role_id: number;is_complete: boolean;countries: Array<number>;team_id?: number;}&DefaultSession['user'];}interfaceUserextendsDefaultUser{role_id: number;// Add role_id to the User typeis_complete: boolean;id: number;countries: Array<number>;team_id?: number;}}declare module 'next-auth/jwt'{interfaceJWT{role_id: number;// Add role_id to the JWT typeis_complete: boolean;id: number;countries: Array<number>;team_id?: number;}}exportdefaultNextAuth({providers: [CredentialsProvider({name: 'Credentials',credentials: {email: {label: 'Email',type: 'email'},password: {label: 'Password',type: 'password'},},asyncauthorize(credentials){constres=awaitfetch('http://127.0.0.1:9123/api/v1/auth/login',{method: 'POST',body: JSON.stringify(credentials),headers: {'Content-Type': 'application/json'},credentials: 'include',});constuser=awaitres.json();if(res.ok&&user){// Add isCompleted directly to the user objectreturn{
...user.data,// isCompleted: false,};}returnnull;},}),],secret: process.env.NEXTAUTH_SECRET!,pages: {signIn: '/auth/login',},session: {strategy: 'jwt',},callbacks: {asyncjwt({ token, user }){// Ensure `isCompleted` is included in the JWTif(user){token.role_id=user.role_id;token.is_complete=user.is_complete;token.id=user.idasnumber;token.countries=user.countries;token.team_id=user.team_id;}returntoken;},asyncsession({ session, token }){// Pass `isCompleted` to the sessionsession.user.role_id=token.role_id;session.user.is_complete=token.is_complete;session.user.id=token.id;session.user.countries=token.countries;session.user.team_id=token.team_id;returnsession;},},});
i tried using cookies().set() from 'nextauth/headers' and it didnt work :
`cookies` was called outside a request scope
Why this happens? normally all cookies should be persisted
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.
-
Hi,
i am having an issue with cookies, i have refresh and access token both sent as cookies.
However when i try to login in using credentials, only the access token is persisted and refresh_token somehow got removed:
i tried using cookies().set() from 'nextauth/headers' and it didnt work :
Why this happens? normally all cookies should be persisted
Beta Was this translation helpful? Give feedback.
All reactions