Next.js Discord

Discord Forum

JWT token have access token. how to get access token on client side or in cookies.

Answered
Highlander posted this in #help-forum
Open in Discord
HighlanderOP
Hi ,
I am using cutom 0auth provider and using nex-auth-example code for it
this below is callback code which is below provider

  ],
  callbacks: {
    async signIn({ user, account, profile, email, credentials }: any) {
      return true;
    },
    async redirect({ url, baseUrl }: any) {
      return baseUrl;
    },
    async session({ session, account, user, token, jwt }: any) {
      console.log(account, "sesion");
      
      return session;
    },

    async jwt({ token, user, account, profile, isNewUser }: any) {
      console.log(account, "jwt");
      return token;
    },
  },
});

i am getting mostly
undefined. on the console log of "jwt". but when i sign in then i get access token. * after sign it is again undefined in the terminal
I want to get this access token outside on the client side so that I can use it to make api call to that providers using it.

i tried use session but they dont have anything in it.
Answered by Highlander
actullay I solved it but idk if its the correct or dirty fix
callbacks: {
    async signIn({ user, account, profile, email, credentials }: any) {
      return true;
    },
    async redirect({ url, baseUrl }: any) {
      return baseUrl;
    },
    async session({ session, account, user, token, jwt }: any) {
     
      console.log(token, " token sesion");
      // console.log(user, "user sesion");
      // console.log(jwt, "jwt session");
    session.user= token
      return session;
    },

    async jwt({ token, user, account, profile, isNewUser }: any) {
      console.log(account,  "jwt" , token);
      return {...token,...account};
    },
  },
View full answer

5 Replies

Are u using jwt or database session?
Using adapters will change the session type to database, unless you specifically change it in the config
HighlanderOP
@Clown i am not using anykind of database
HighlanderOP
actullay I solved it but idk if its the correct or dirty fix
callbacks: {
    async signIn({ user, account, profile, email, credentials }: any) {
      return true;
    },
    async redirect({ url, baseUrl }: any) {
      return baseUrl;
    },
    async session({ session, account, user, token, jwt }: any) {
     
      console.log(token, " token sesion");
      // console.log(user, "user sesion");
      // console.log(jwt, "jwt session");
    session.user= token
      return session;
    },

    async jwt({ token, user, account, profile, isNewUser }: any) {
      console.log(account,  "jwt" , token);
      return {...token,...account};
    },
  },
Answer
HighlanderOP
now from client side if I print the useSession data then it prints out access token