rafa
Implementing and Persisting UUIDs for User Sessions in Nuxt 3
Hello there,
I'm currently developing an application using Nuxt 3 and I need to integrate a specific functionality. I'm unsure about the correct implementation approach and would appreciate some guidance.
Functionality Requirements: When a user visits the site, I need to make a call to an external API that returns a unique UUID for that user. This UUID should be stored in the browser's localStorage to prevent the generation of a new UUID on subsequent visits. Additionally, this UUID needs to be included in the headers of all $fetch() calls made to the API.
Current Implementation: I have created a server plugin that makes a $fetch call to the API and successfully retrieves a UUID. My challenge now is to store this UUID in localStorage and ensure it's included in the headers of all $fetch() calls within the server/api/items.ts file, where I make additional API requests.
Questions: Could anyone assist by explaining how to:
Store the UUID in localStorage correctly?
Pass this UUID as a header in all $fetch calls made from server-side API routes?
Thank you in advance for any help you can provide!
5 replies