Skip to content

Commit

Permalink
fix(useStrapiToken): implement caching
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac committed Dec 20, 2021
1 parent ce1be74 commit 6e25a4a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/composables/useStrapiToken.ts
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
}

0 comments on commit 6e25a4a

Please sign in to comment.