best Client side session management for nextjs?
Answered
Spectacled bear posted this in #help-forum
Spectacled bearOP
Hi, im using nextjs with spring boot as backend, i want to have a client side session to hold some data fetched from db, like username. I dont want to store username in localstorage as it can be updated manually. Im thinking to start a session when user comes to site for sometime, and will read data from there until it expires.
Answered by Southern rough shrimp
Yeah, but you can also pass your token to springboot to authenticate requests
12 Replies
Southern rough shrimp
Spectacled bearOP
im using google oauth from backend(spring boot), That means the oauth flow runs from backend not from the client side. From frontend im just redirecting the user to backend to signin
Southern rough shrimp
Well since nextjs is a backend too, you should probably have set up the auth on nextjs' side
Then have a private connection between nextjs and sprintboot api
That's what we have set up at work
@Southern rough shrimp https://authjs.dev/
Southern rough shrimp
Use this, with the google oauth integration, then set up your server actions to first check the user's logged in, then talk to springboot
Spectacled bearOP
but the token will be generated from nextjs rather spring boot
Southern rough shrimp
Yeah, but you can also pass your token to springboot to authenticate requests
Answer
Southern rough shrimp
1. Click 'Log in' via nextjs (with Authjs)
2. Enter credentials
3. Receive token from Google oauth
4. Make a request to springboot, passing this newly acquired token
2. Enter credentials
3. Receive token from Google oauth
4. Make a request to springboot, passing this newly acquired token
Spectacled bearOP
I got the idea from your first message but thanks for explaining so well.
Southern rough shrimp
if it solves your issue could you mark the solution please