Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
feat: add getSession method to refresh auth
Browse files Browse the repository at this point in the history
  • Loading branch information
ronger-x committed Apr 28, 2024
1 parent 2ac439b commit 67815ca
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/runtime/composables/refresh/use-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof useLocalAuth>['getSession'] = async (getSessionOptions = {}) => {
const getSession: ReturnType<typeof useLocalAuth>['getSession'] = async (
getSessionOptions = {},
) => {
const config = useTypedConfig(useRuntimeConfig(), 'refresh')
const { path, method } = config.endpoints.getSession

Expand All @@ -21,14 +24,14 @@ const getSession: ReturnType<typeof useLocalAuth>['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

Expand Down

0 comments on commit 67815ca

Please sign in to comment.