From 20b60253c503d7cba0cc11937f55422302f6bd13 Mon Sep 17 00:00:00 2001 From: Zoey Date: Thu, 4 Jul 2024 18:31:10 +0200 Subject: [PATCH 1/2] Revert "fix: properly disable `getSession` endpoint for local and refresh" (#788) --- src/runtime/composables/local/useAuth.ts | 37 +++++++++++------------- src/runtime/types.ts | 4 +-- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/runtime/composables/local/useAuth.ts b/src/runtime/composables/local/useAuth.ts index e2a60e3a..63cea938 100644 --- a/src/runtime/composables/local/useAuth.ts +++ b/src/runtime/composables/local/useAuth.ts @@ -76,7 +76,7 @@ const getSession: GetSessionFunc = async (getSessionO const nuxt = useNuxtApp() const config = useTypedBackendConfig(useRuntimeConfig(), 'local') - const getSessionConfig = config.endpoints.getSession + const { path, method } = config.endpoints.getSession const { data, loading, lastRefreshedAt, rawToken, token: tokenState, _internal } = useAuthState() let token = tokenState.value @@ -88,27 +88,24 @@ const getSession: GetSessionFunc = async (getSessionO return } - if (getSessionConfig) { - const headers = new Headers(token ? { [config.token.headerName]: token } as HeadersInit : undefined) - const { path, method } = getSessionConfig - - loading.value = true - try { - const result = await _fetch(nuxt, path, { method, headers }) - const { dataResponsePointer: sessionDataResponsePointer } = config.session - data.value = jsonPointerGet(result, sessionDataResponsePointer) - } catch (err) { - if (!data.value && err instanceof Error) { - console.error(`Session: unable to extract session, ${err.message}`) - } - - // Clear all data: Request failed so we must not be authenticated - data.value = null - rawToken.value = null + const headers = new Headers(token ? { [config.token.headerName]: token } as HeadersInit : undefined) + + loading.value = true + try { + const result = await _fetch(nuxt, path, { method, headers }) + const { dataResponsePointer: sessionDataResponsePointer } = config.session + data.value = jsonPointerGet(result, sessionDataResponsePointer) + } catch (err) { + if (!data.value && err instanceof Error) { + console.error(`Session: unable to extract session, ${err.message}`) } - loading.value = false - lastRefreshedAt.value = new Date() + + // Clear all data: Request failed so we must not be authenticated + data.value = null + rawToken.value = null } + loading.value = false + lastRefreshedAt.value = new Date() const { required = false, callbackUrl, onUnauthenticated, external } = getSessionOptions ?? {} if (required && data.value === null) { diff --git a/src/runtime/types.ts b/src/runtime/types.ts index 05313d8e..61954bbb 100644 --- a/src/runtime/types.ts +++ b/src/runtime/types.ts @@ -96,15 +96,13 @@ export type ProviderLocal = { signUp?: { path?: string; method?: RouterMethod }; /** * 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. - * Set to false to disable. * * 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....` * * @default { path: '/session', method: 'get' } * @example { path: '/user', method: 'get' } - * @example false */ - getSession?: { path?: string; method?: RouterMethod } | false; + getSession?: { path?: string; method?: RouterMethod }; }; /** * Pages that `nuxt-auth` needs to know the location off for redirects. From b2ad71a9d572fb3237a4c5fb32475773437d1c9f Mon Sep 17 00:00:00 2001 From: Zoey Date: Thu, 4 Jul 2024 18:34:28 +0200 Subject: [PATCH 2/2] release: 0.8.0 (#789) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 88ae6cc6..42ab899f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sidebase/nuxt-auth", - "version": "0.8.0-rc.1", + "version": "0.8.0", "license": "MIT", "type": "module", "exports": {