diff --git a/docs/guide/application-side/session-access.md b/docs/guide/application-side/session-access.md index 90cd821c..0d89c80c 100644 --- a/docs/guide/application-side/session-access.md +++ b/docs/guide/application-side/session-access.md @@ -210,6 +210,9 @@ await signIn(credentials, { callbackUrl: '/protected' }) // Trigger a signIn with a redirect to an external page afterwards await signIn(credentials, { callbackUrl: 'https://nuxt.org', external: true }) + +// Trigger a signIn without calling getSession directly. You have to manually call it to get session data. +await signIn(credentials, { callGetSession: false }) ``` ::: @@ -321,6 +324,7 @@ setToken('new token') // Helper method to quickly delete the token cookie (alias for rawToken.value = null) clearToken() ``` + ::: :::warning Local provider: diff --git a/src/runtime/composables/local/useAuth.ts b/src/runtime/composables/local/useAuth.ts index 60ce39ce..66939324 100644 --- a/src/runtime/composables/local/useAuth.ts +++ b/src/runtime/composables/local/useAuth.ts @@ -55,9 +55,12 @@ const signIn: SignInFunc = async (credentials, signInOptions, rawRefreshToken.value = extractedRefreshToken } - await nextTick(getSession) + const { redirect = true, external, callGetSession = true } = signInOptions ?? {} + + if (callGetSession) { + await nextTick(getSession) + } - const { redirect = true, external } = signInOptions ?? {} let { callbackUrl } = signInOptions ?? {} if (typeof callbackUrl === 'undefined') { const redirectQueryParam = useRoute()?.query?.redirect diff --git a/src/runtime/types.ts b/src/runtime/types.ts index dc225b69..14545cd7 100644 --- a/src/runtime/types.ts +++ b/src/runtime/types.ts @@ -563,6 +563,12 @@ export interface SecondarySignInOptions extends Record { * @default false */ external?: boolean + /** + * Whether `getSession` needs to be called after a successful sign-in. When set to false, you can manually call `getSession` to obtain the session data. + * + * @default true + */ + callGetSession?: boolean } export interface SignUpOptions extends SecondarySignInOptions {