From 67815ca261b3b14335e7df93b839b3011fa1888b Mon Sep 17 00:00:00 2001 From: ronger Date: Sun, 28 Apr 2024 11:33:07 +0800 Subject: [PATCH] feat: add getSession method to refresh auth --- src/runtime/composables/refresh/use-auth.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/runtime/composables/refresh/use-auth.ts b/src/runtime/composables/refresh/use-auth.ts index 8119af7..929519c 100644 --- a/src/runtime/composables/refresh/use-auth.ts +++ b/src/runtime/composables/refresh/use-auth.ts @@ -6,12 +6,15 @@ import { useAuthFetch } from '../use-auth-fetch' import { logger } from '../../utils/logger' import { useAuth as useLocalAuth } from '../local/use-auth' import { useAuthState } from './use-auth-state' +import type { SessionData } from '#auth' import { navigateTo, useRuntimeConfig } from '#imports' /** * 请求用户权限数据 */ -const getSession: ReturnType['getSession'] = async (getSessionOptions = {}) => { +const getSession: ReturnType['getSession'] = async ( + getSessionOptions = {}, +) => { const config = useTypedConfig(useRuntimeConfig(), 'refresh') const { path, method } = config.endpoints.getSession @@ -21,14 +24,14 @@ const getSession: ReturnType['getSession'] = async (getSess if (!authToken && !getSessionOptions.force) { if (refreshToken.value) { - await refresh({refreshToken: refreshToken.value}) + await refresh({ refreshToken: refreshToken.value }) authToken = useAuthState().token.value } else { return } } - const headers = new Headers(token.value ? { [config.token.headerName]: authToken } : undefined) + const headers = new Headers(authToken ? { [config.token.headerName]: authToken } : undefined) loading.value = true