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": { 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.