Persist user info and auth token via Zustand or Redux toolkit
Unanswered
Northeast Congo Lion posted this in #help-forum
Northeast Congo LionOP
Hello. I am using Next.js 15 (App router) as the frontend of my personal project and I want to persist the user info and access token sent from the backend where both will be accessible in server and client side. How can I do that with either Zustand or Redux toolkit? Is there a better alternative?
5 Replies
I personally use Redux but that depends
Do you have a Single Page Application?
Do you have a Single Page Application?
@!Blackflame I personally use Redux but that depends
Do you have a Single Page Application?
Northeast Congo LionOP
I am using Next.js so I was hoping to access user role and access token for middleware and API calls from either server or client components.
I usually use Redux as well and for page router there is proper support, but not sure what to do about app router.
@Northeast Congo Lion I usually use Redux as well and for page router there is proper support, but not sure what to do about app router.
Have you implemented oAuth in your apps before?
never keep access tokens on server side those are for server side use and used to make requests to the service provider on behalf of the user
In the wrong hands this can be very bad
never keep access tokens on server side those are for server side use and used to make requests to the service provider on behalf of the user
In the wrong hands this can be very bad
Northeast Congo LionOP
I am implementing JWT authentication so I need to pass access token in auth header. Since React now uses server component, there will be issue with localStorage access and so I am opting to store it in some way in a cookie to use it in the auth header when making API calls regardless whether it is in server side or client side. Previously, using next-redux-wrapper and cookie-wrapper with page router, it was possible to get the access token in both server side and client side as well as persist user state in redux for both sides as well but not sure what to do in Next.js 15 app router.