Skip to content

Commit

Permalink
fix: allow useGqlToken to remove stored tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Diizzayy committed Nov 3, 2022
1 parent edae96d commit 6fb74d4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/runtime/composables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,19 @@ export function useGqlToken (...args: any[]) {

const tokenStorage = (useRuntimeConfig()?.public?.['graphql-client'] as GqlConfig)?.clients?.[client]?.tokenStorage

if (token && typeof tokenStorage === 'object') {
if (token !== undefined && typeof tokenStorage === 'object') {
if (tokenStorage.mode === 'cookie') {
const cookie = useCookie(tokenStorage.name, tokenStorage.cookieOptions)

cookie.value = token
}

if (process.client && tokenStorage.mode === 'localStorage') {
localStorage.setItem(tokenStorage.name, token)
if (token !== null) {
localStorage.setItem(tokenStorage.name, token)
} else {
localStorage.removeItem(tokenStorage.name)
}
}
}

Expand Down

0 comments on commit 6fb74d4

Please sign in to comment.