State Management
What is the recommended way to manage the state globally in a Nuxt app? Does useState persist data on the server? If not, how do we handle global information like a JWT token in a Nuxt app so that we can access it from any page/component across refreshes?
1 Reply
To handle state you can use named useState (built-in) or a state manage like Pinia.
Basically like you would in a vue project.
useState only persists in the client but in some cases it can get it's initial value from the server.
Since I guess Cookies, Local- and Session storage don't do the trick.
https://github.com/sidebase/nuxt-session
This might be what you are looking for.
An alternative would be using a session token and building your own server routes to handle the session management.
GitHub
GitHub - sidebase/nuxt-session: Nuxt session middleware to get a pe...
Nuxt session middleware to get a persistent session per app user, e.g., to store data across multiple requests. The nuxt session module provides the useSession() composable out of the box and sets ...