Skip to content

Commit

Permalink
feat: add set and clear token methods
Browse files Browse the repository at this point in the history
  • Loading branch information
IsraelOrtuno committed Oct 23, 2023
1 parent b5433a0 commit e0cfa48
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/runtime/composables/local/useAuthState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import type { SessionData } from '#auth'

interface UseAuthStateReturn extends CommonUseAuthStateReturn<SessionData> {
token: ComputedRef<string | null>
rawToken: CookieRef<string | null>
rawToken: CookieRef<string | null>,
setToken: (newToken: string | null) => void
clearToken: () => void
}

export const useAuthState = (): UseAuthStateReturn => {
Expand All @@ -29,14 +31,24 @@ export const useAuthState = (): UseAuthStateReturn => {
return config.token.type.length > 0 ? `${config.token.type} ${rawToken.value}` : rawToken.value
})

const setToken = (newToken: string | null) => {
rawToken.value = newToken
}

const clearToken = () => {
setToken(null)
}

const schemeSpecificState = {
token,
rawToken
}

return {
...commonAuthState,
...schemeSpecificState
...schemeSpecificState,
setToken,
clearToken
}
}
export default useAuthState

0 comments on commit e0cfa48

Please sign in to comment.