Skip to content

Commit 20b6025

Browse files
authored
Revert "fix: properly disable getSession endpoint for local and refresh" (#788)
1 parent cb3db19 commit 20b6025

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

src/runtime/composables/local/useAuth.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const getSession: GetSessionFunc<SessionData | null | void> = async (getSessionO
7676
const nuxt = useNuxtApp()
7777

7878
const config = useTypedBackendConfig(useRuntimeConfig(), 'local')
79-
const getSessionConfig = config.endpoints.getSession
79+
const { path, method } = config.endpoints.getSession
8080
const { data, loading, lastRefreshedAt, rawToken, token: tokenState, _internal } = useAuthState()
8181

8282
let token = tokenState.value
@@ -88,27 +88,24 @@ const getSession: GetSessionFunc<SessionData | null | void> = async (getSessionO
8888
return
8989
}
9090

91-
if (getSessionConfig) {
92-
const headers = new Headers(token ? { [config.token.headerName]: token } as HeadersInit : undefined)
93-
const { path, method } = getSessionConfig
94-
95-
loading.value = true
96-
try {
97-
const result = await _fetch<any>(nuxt, path, { method, headers })
98-
const { dataResponsePointer: sessionDataResponsePointer } = config.session
99-
data.value = jsonPointerGet<SessionData>(result, sessionDataResponsePointer)
100-
} catch (err) {
101-
if (!data.value && err instanceof Error) {
102-
console.error(`Session: unable to extract session, ${err.message}`)
103-
}
104-
105-
// Clear all data: Request failed so we must not be authenticated
106-
data.value = null
107-
rawToken.value = null
91+
const headers = new Headers(token ? { [config.token.headerName]: token } as HeadersInit : undefined)
92+
93+
loading.value = true
94+
try {
95+
const result = await _fetch<any>(nuxt, path, { method, headers })
96+
const { dataResponsePointer: sessionDataResponsePointer } = config.session
97+
data.value = jsonPointerGet<SessionData>(result, sessionDataResponsePointer)
98+
} catch (err) {
99+
if (!data.value && err instanceof Error) {
100+
console.error(`Session: unable to extract session, ${err.message}`)
108101
}
109-
loading.value = false
110-
lastRefreshedAt.value = new Date()
102+
103+
// Clear all data: Request failed so we must not be authenticated
104+
data.value = null
105+
rawToken.value = null
111106
}
107+
loading.value = false
108+
lastRefreshedAt.value = new Date()
112109

113110
const { required = false, callbackUrl, onUnauthenticated, external } = getSessionOptions ?? {}
114111
if (required && data.value === null) {

src/runtime/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,13 @@ export type ProviderLocal = {
9696
signUp?: { path?: string; method?: RouterMethod };
9797
/**
9898
* What method and path to call to fetch user / session data from. `nuxt-auth` will send the token received upon sign-in as a header along this request to authenticate.
99-
* Set to false to disable.
10099
*
101100
* Refer to the `token` configuration to configure how `nuxt-auth` uses the token in this request. By default it will be send as a bearer-authentication header like so: `Authentication: Bearer eyNDSNJDASNMDSA....`
102101
*
103102
* @default { path: '/session', method: 'get' }
104103
* @example { path: '/user', method: 'get' }
105-
* @example false
106104
*/
107-
getSession?: { path?: string; method?: RouterMethod } | false;
105+
getSession?: { path?: string; method?: RouterMethod };
108106
};
109107
/**
110108
* Pages that `nuxt-auth` needs to know the location off for redirects.

0 commit comments

Comments
 (0)