Next.js Discord

Discord Forum

How to get session

Unanswered
American black bear posted this in #help-forum
Open in Discord
Avatar
American black bearOP
Hello, how can i get data session from /api/auth/session without spamming the website and the token will changed anytime?

20 Replies

Avatar
goodsie
Avatar
American black bearOP
the issue is not about this
that the issue
Image
if im trying to use "useSession" that will end the app
like
spamming error
Avatar
goodsie
What do you have in [...nextauth]
Avatar
American black bearOP
route.ts but i fixed by :
    callbacks: {
      async jwt({ token, account, profile }) {
        if (account) {
          token.accessToken = account.access_token
          token.id = profile.id
        }
        return token
      }
    },

But i have other problem when im use "pages" on next-auth to "/login" so i get 'Missing "code_verifier"'
like
pages: {
  'signIn': '/login'
}
Avatar
goodsie
You are using pages router method?
Avatar
American black bearOP
App router method
Image
Avatar
goodsie
I did this for callbacks:
  callbacks: {
    async jwt({ token, user }) {
      if (user) token.user = user;
      return token;
    },

    async session({ session, token }) {
      session.user = token.user;
      session.tier = token.tier;
      return session
    }
  },
Avatar
American black bearOP
im feel so stupid when i was with folder calling "login" so that why that saying "code_verifier"
:lolsob:
Avatar
goodsie
🤣
Avatar
American black bearOP
let me fix about the "pages" because im keeping get 404 (i hate this)
this im mean
Avatar
American black bearOP
@goodsie if im making App router login how im add to link about the state?