From 28016dbdc2a7b77ead0f2bb8c00bd87b84fdc440 Mon Sep 17 00:00:00 2001 From: benjipott Date: Tue, 14 Nov 2023 12:31:46 +0100 Subject: [PATCH] fix: lint --- src/runtime/composables/local/useAuth.ts | 25 +++++++------------ src/runtime/composables/local/useAuthState.ts | 2 +- src/runtime/types.ts | 4 ++- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/runtime/composables/local/useAuth.ts b/src/runtime/composables/local/useAuth.ts index 385d59b5..521e9a86 100644 --- a/src/runtime/composables/local/useAuth.ts +++ b/src/runtime/composables/local/useAuth.ts @@ -1,10 +1,10 @@ -import { callWithNuxt } from '#app/nuxt' import { readonly, Ref } from 'vue' import { jsonPointerGet, useTypedBackendConfig } from '../../helpers' import { CommonUseAuthReturn, GetSessionFunc, SecondarySignInOptions, SignInFunc, SignOutFunc } from '../../types' import { getRequestURLWN } from '../../utils/callWithNuxt' import { _fetch } from '../../utils/fetch' import { useAuthState } from './useAuthState' +import { callWithNuxt } from '#app/nuxt' // @ts-expect-error - #auth not defined import type { SessionData } from '#auth' import { navigateTo, nextTick, useNuxtApp, useRuntimeConfig } from '#imports' @@ -43,21 +43,20 @@ const signIn: SignInFunc = async (credentials, signInOptions, } } - const addHeaders = (token: string | null, config: ReturnType) => { if (!(token && config.token.headerName)) { return undefined } if (config.token.type.length > 0) { - switch (config.token.type) { - case 'Cookie': - return { [config.token.headerName]: `${config.token.name}=${token}` } - case 'Bearer': - default: - return { [config.token.headerName]: `${config.token.type} ${token}`} - } + switch (config.token.type) { + case 'Cookie': + return { [config.token.headerName]: `${config.token.name}=${token}` } + case 'Bearer': + default: + return { [config.token.headerName]: `${config.token.type} ${token}` } } + } } const signOut: SignOutFunc = async (signOutOptions) => { @@ -131,13 +130,7 @@ const signUp = async (credentials: Credentials, signInOptions?: SecondarySignInO body: credentials }) - await nextTick(getSession) - - const { callbackUrl, redirect = true, external } = signInOptions ?? {} - if (redirect) { - const urlToNavigateTo = callbackUrl ?? await getRequestURLWN(nuxt) - return navigateTo(urlToNavigateTo, { external }) - } + return signIn(credentials, signInOptions) } interface UseAuthReturn extends CommonUseAuthReturn { diff --git a/src/runtime/composables/local/useAuthState.ts b/src/runtime/composables/local/useAuthState.ts index 18e4ddb7..1a9fa375 100644 --- a/src/runtime/composables/local/useAuthState.ts +++ b/src/runtime/composables/local/useAuthState.ts @@ -19,7 +19,7 @@ export const useAuthState = (): UseAuthStateReturn => { const commonAuthState = makeCommonAuthState() // Re-construct state from cookie, also setup a cross-component sync via a useState hack, see https://github.com/nuxt/nuxt/issues/13020#issuecomment-1397282717 - const _rawTokenCookie = useCookie(config.token.name, { default: () => null, maxAge: config.token.maxAgeInSeconds, sameSite: config.token.sameSiteAttribute, secure: config.token.secure, domain: config.token.domain }) + const _rawTokenCookie = useCookie(config.token.name, { default: config.token.default, maxAge: config.token.maxAgeInSeconds, sameSite: config.token.sameSiteAttribute, secure: config.token.secure, domain: config.token.domain }) const rawToken = useState('auth:raw-token', () => _rawTokenCookie.value) watch(rawToken, () => { _rawTokenCookie.value = rawToken.value }) diff --git a/src/runtime/types.ts b/src/runtime/types.ts index 0156fc85..899c5288 100644 --- a/src/runtime/types.ts +++ b/src/runtime/types.ts @@ -125,6 +125,8 @@ type ProviderLocal = { * @default auth:token Access the cookie `auth:token` from session */ name?: string, + + default?: () => string | null /** * How to extract the authentication-token from the sign-in response. * @@ -179,7 +181,7 @@ type ProviderLocal = { * @default undefined use * @example 'domain.com' */ - domain?: boolean, + domain?: string, }, /**