Next.js Discord

Discord Forum

How can I properly update the session using next-auth?

Unanswered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Northeast Congo LionOP
Below is my team's login flow :

1. First, let user login through GoogleProvider
2. Right after the user logged in, it will get jwt token containing access_token.
3. I have to send this access_token to my teammate's server, to ensure that our client is logged in.
So this would be the POST api call, to the endpoint of my teammate's server (http://.../user/login)
4. If the POST api call is successful, it will return a new access_token_from_server (this is manually generated from my teammate's server).
5. Then I can change the UI to the user that he/she is logged in.
6. When the user wants to logout, it has to send PUT request to my teammate's server endpoint (http://.../user/logout), with the parameter access_token_from_server which is given by the server.

I created @/app/api/auth/[...nextauth]/route.ts,
and @/utils/auth.ts for next-auth configuration.
I'm using useSession() hook on my client side, signIn() for login, and signOut() for logout.
I'm confusing where should I start to update my session's access_token with the one from my teammate's server.

0 Replies