[Solved] Storing a user object globally
Greetings! I want to store a user object globally after parsing a JWT in a server plugin, and I seem to only get this partially right. Why am I doing this? Because where my Nuxt app is deployed, authentication happens before the web traffic reaches the Nuxt app. In the request I can see a header with the JWT that has the user info.
What I want to happen (which I accomplished easily in Flask in my previous website) is:
I appreciate any insight into how I can solve this problem, even if it's something different than this current solution. Thanks!
What I want to happen (which I accomplished easily in Flask in my previous website) is:
- before any page loads, check if there is a user already in a context/global object. If so, continue. If not, we need to check the request header.
- parse the JWT in the request header
- get the user data from a local database
- store the user object in a app-level state somewhere
- get the user info in the templates
I appreciate any insight into how I can solve this problem, even if it's something different than this current solution. Thanks!
Stack Overflow
Using Nuxt 3. Currently I can parse a JWT in the server middleware to get the logged in user, but I want to save that logged in user info to a global variable. Then, on the client side I want to ge...