diff --git a/src/module.ts b/src/module.ts index 1e0fb3cc..96b6a51f 100644 --- a/src/module.ts +++ b/src/module.ts @@ -36,8 +36,11 @@ const defaultsByBackend: { [key in SupportedAuthProviders]: DeepRequired null, sameSiteAttribute: 'lax', - name: 'auth:token' + name: 'auth:token', + secure: false, + domain: '' }, sessionDataType: { id: 'string | number' } }, diff --git a/src/runtime/composables/local/useAuthState.ts b/src/runtime/composables/local/useAuthState.ts index 0a4aff7e..cb65a6c4 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 497d2290..12f3aab5 100644 --- a/src/runtime/types.ts +++ b/src/runtime/types.ts @@ -116,6 +116,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. * @@ -149,7 +151,7 @@ type ProviderLocal = { * @default undefined * @example 60 * 60 * 24 */ - maxAgeInSeconds?: number | undefined, + maxAgeInSeconds?: number, /** * The cookie sameSite policy. See the specification here: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7 * @@ -167,11 +169,11 @@ type ProviderLocal = { /** * Specifies the value for the Domain Set-Cookie attribute. By default, no domain is set, and most clients will consider applying the cookie only to the current domain. * - * @default undefined use + * @default undefined use * @example 'domain.com' */ - domain?: boolean, - + domain?: string, + }, /** * Define an interface for the session data object that `nuxt-auth` expects to receive from the `getSession` endpoint.