diff --git a/src/runtime/composables/local/useAuthState.ts b/src/runtime/composables/local/useAuthState.ts index 06ab54ec..b12f6b6d 100644 --- a/src/runtime/composables/local/useAuthState.ts +++ b/src/runtime/composables/local/useAuthState.ts @@ -9,7 +9,9 @@ import type { SessionData } from '#auth' interface UseAuthStateReturn extends CommonUseAuthStateReturn { token: ComputedRef - rawToken: CookieRef + rawToken: CookieRef, + setToken: (newToken: string | null) => void + clearToken: () => void } export const useAuthState = (): UseAuthStateReturn => { @@ -29,6 +31,14 @@ 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 @@ -36,7 +46,9 @@ export const useAuthState = (): UseAuthStateReturn => { return { ...commonAuthState, - ...schemeSpecificState + ...schemeSpecificState, + setToken, + clearToken } } export default useAuthState