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
We have a project built with React, Next.js, and a Laravel backend.
We're using four authentication providers: CredentialsProvider, YandexProvider, VkProvider, and MailRuProvider.
Is it considered a good practice to make a request to the Laravel backend in the session callback to retrieve user profile data?
We’ve noticed that there are frequent requests to /session, and each callback seems to trigger additional requests.
next-auth = ^5.0.0-beta.29
Here's a code snippet showing the HTTP requests:
exportconst{ handlers, signIn, signOut, auth }=NextAuth({trustHost: true,providers: [YandexProvider({/* code */}),VkProvider({/* code */}),],callbacks: {asyncjwt({ token, user, account, profile, trigger, session }){if(account?.provider==='yandex'){constemail=profile.emails[0]constdata=awaitcheck({email: email})if(!data.data.user_exist){constuser={// ... fill props}constdata=awaitregister(user)if(data){const{ user,token: access_token, refresh_token }=data.datatoken.user={// ... fill props}// save token for get profiletoken.token=access_tokentoken.refreshToken=refresh_token}}else{constuser={// ... fill props}constdata=awaitlogin(user)if(data){const{ user,token: access_token, refresh_token }=data.datatoken.user={// ... fill props}// save token for get profiletoken.token=access_tokentoken.refreshToken=refresh_token}}}returntoken},asyncsession({ session, token, user }){constaccess_token=token.tokenconstrefresh_token=token.refreshTokenif(token){constresponse=awaitfetch(`${process.env.NEXT_PUBLIC_API_URL}/profile`,{method: 'GET',headers: {Authorization: 'Bearer '+access_token,'Content-Type': 'application/json'}})if(!response.ok){thrownewError('Network response was not ok '+response.statusText)}session.user={// ... code// access_token from jwt callbackaccessToken: access_token,refreshToken: refresh_token}}returnsession}},})
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.
-
We have a project built with React, Next.js, and a Laravel backend.
We're using four authentication providers: CredentialsProvider, YandexProvider, VkProvider, and MailRuProvider.
Is it considered a good practice to make a request to the Laravel backend in the session callback to retrieve user profile data?
We’ve noticed that there are frequent requests to /session, and each callback seems to trigger additional requests.
next-auth = ^5.0.0-beta.29
Here's a code snippet showing the HTTP requests:
Beta Was this translation helpful? Give feedback.
All reactions