Compare commits

...

5 Commits

Author SHA1 Message Date
Angelo Schuler Piletti
c01dc95b94
Merge b7f0369e79 into 9bf8465806 2024-11-19 23:30:27 +02:00
Angelo Schuler Piletti
b7f0369e79
Merge branch 'main' into main 2024-10-28 14:57:37 +01:00
Angelo Schuler Piletti
35e8572b63
Merge branch 'main' into main 2024-10-28 14:34:43 +01:00
autofix-ci[bot]
1b885c9049
[autofix.ci] apply automated fixes 2024-10-15 02:38:35 +00:00
angelo
580cc68024 docs: Add example for handling authentication with useCookie in Nuxt docs 2024-10-15 04:26:50 +02:00

View File

@ -231,3 +231,36 @@ export default defineEventHandler(event => {
```
:link-example{to="/docs/examples/advanced/use-cookie"}
## Handling Authentication with Cookies
You can manage authentication tokens using cookies like this:
```ts [plugins/auth.ts]
export default defineNuxtPlugin(() => {
const nuxtApp = useNuxtApp()
const authStore = useAuthStore()
const accessToken = useCookie('accessToken', {
sameSite: 'strict',
})
return {
provide: {
getAccessToken() {
return accessToken.value
},
setAccessToken(accessToken: string) {
accessToken.value = accessToken
},
loginUser(user: User) {
nuxtApp.$setAccessToken(user.accessToken)
authStore.setUser(user)
},
logout() {
nuxtApp.$setAccessToken('')
authStore.logout()
},
},
}
})
```