N
Nuxt3mo ago
Viktor

Supabase Authentication

i'm using nuxt3 with supabase, and when i'm logged in authentication token persist in cookies all time, how to configure this ?
2 Replies
kapa.ai
kapa.ai3mo ago
Hi @Viktor. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To control how long the Supabase authentication token persists in cookies in your Nuxt 3 app, you need to configure the cookie's expiration settings. In Nuxt, you can use the useCookie composable to manage cookies, including setting their expiration with the maxAge (in seconds) or expires (Date object) options. If you don't set these options, the cookie will be session-only and removed when the browser is closed. If you want the token to persist for a specific duration, set maxAge or expires accordingly. Example:
const accessToken = useCookie('accessToken', {
maxAge: 60 * 60 * 24 * 7 // 7 days in seconds
})
const accessToken = useCookie('accessToken', {
maxAge: 60 * 60 * 24 * 7 // 7 days in seconds
})
This will make the accessToken cookie persist for 7 days. Adjust the value as needed for your use case. If you want the cookie to be removed when the browser closes, simply omit maxAge and expires options. For more details, see the official documentation on cookie expiration options: Nuxt useCookie: maxAge / expires. If you're using the Supabase Nuxt module, check if it exposes options for cookie configuration, or manage the cookies directly as shown above. If you need to remove the token (e.g., on logout), set the cookie value to undefined:
accessToken.value = undefined
accessToken.value = undefined
This approach works both on the client and server side in Nuxt 3 apps Nuxt useCookie composable. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@1175817169779556363> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?