-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(useStrapiToken): implement caching
- Loading branch information
1 parent
ce1be74
commit 6e25a4a
Showing
1 changed file
with
13 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
import { useCookie } from '#app' | ||
import { useCookie, useNuxtApp } from '#app' | ||
|
||
export const useStrapiToken = () => useCookie<string | null>('strapi_jwt') | ||
export const useStrapiToken = () => { | ||
const nuxtApp = useNuxtApp() | ||
|
||
nuxtApp._cookies = nuxtApp._cookies || {} | ||
if (nuxtApp._cookies.strapi_jwt) { | ||
return nuxtApp._cookies.strapi_jwt | ||
} | ||
|
||
const cookie = useCookie<string | null>('strapi_jwt') | ||
nuxtApp._cookies.strapi_jwt = cookie | ||
return cookie | ||
} |