N
Nuxt2mo ago
LordGhandi

Storing jwt token with nuxt-auth-utils

Does nuxt-auth-utils support storing normal jwt tokens inside the session object?
2 Replies
kapa.ai
kapa.ai2mo ago
Hi @LordGhandi. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The knowledge sources indicate that nuxt-auth-utils manages session data using secured and sealed cookies, and you can store arbitrary data inside the session object, such as user information. For example, in the login API route, the session is set with a user object:
await setUserSession(event, {
user: {
name: 'John Doe'
}
})
await setUserSession(event, {
user: {
name: 'John Doe'
}
})
While the documentation and examples show storing user objects, they do not explicitly mention storing a raw JWT token. However, since the session object can hold arbitrary data, you should be able to store a JWT token as a property (e.g., token) within the session object:
await setUserSession(event, {
user: {
name: 'John Doe'
},
token: 'your-jwt-token-here'
})
await setUserSession(event, {
user: {
name: 'John Doe'
},
token: 'your-jwt-token-here'
})
This approach aligns with the way session data is managed in nuxt-auth-utils, but the documentation does not explicitly confirm or deny support for storing raw JWT tokens. Therefore, while it appears possible, please note that this is inferred from the general usage of the session object and not directly stated in the documentation Sessions and Authentication. If you need to access the token on the client side, you can retrieve it from the session using the useUserSession composable:
const { session } = useUserSession()
console.log(session.value.token) // your-jwt-token-here
const { session } = useUserSession()
console.log(session.value.token) // your-jwt-token-here
In summary: nuxt-auth-utils appears to support storing a JWT token inside the session object, but this is not explicitly documented. Use with caution and test to ensure it meets your requirements. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@358749735323959308> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?