From 0d9ae7a9dd7a7136a4713b37405442b6eeda1069 Mon Sep 17 00:00:00 2001 From: "Soheil Nazari [CHECK24]" <113988347+s0h311@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:54:53 +0100 Subject: [PATCH 1/2] docs: update installation.md (#955) * docs: update installation.md, @sidebase/nuxt-auth should be installed as regular dep @sidebase/nuxt-auth should be installed as a regular dependency instead of a dev dependency. Also added additional scripts for yarn and pnpm * revert to dev dep * Update docs/guide/getting-started/installation.md * Update docs/guide/getting-started/installation.md --------- Co-authored-by: Marsel Shaikhin <18054980+phoenix-ru@users.noreply.github.com> --- docs/guide/getting-started/installation.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/guide/getting-started/installation.md b/docs/guide/getting-started/installation.md index 20283adb..7fde490a 100644 --- a/docs/guide/getting-started/installation.md +++ b/docs/guide/getting-started/installation.md @@ -2,10 +2,22 @@ You can install NuxtAuth using nuxi: -```bash -npx nuxi@latest module add sidebase-auth +::: code-group + +```bash [npm] +npx nuxi module add sidebase-auth +``` + +```bash [pnpm] +pnpm exec nuxi module add sidebase-auth ``` +```bash [yarn] +yarn dlx nuxi module add sidebase-auth +``` + +::: + ::: details Manual installation ::: code-group @@ -19,7 +31,7 @@ pnpm i -D @sidebase/nuxt-auth ``` ```bash [yarn] -yarn add --dev @sidebase/nuxt-auth +yarn add -D @sidebase/nuxt-auth ``` ::: @@ -31,7 +43,7 @@ Add NuxtAuth to your `nuxt.config`: ```ts [nuxt.config.ts] export default defineNuxtConfig({ modules: [ - '@sidebase/nuxt-auth', + '@sidebase/nuxt-auth' ], }) ``` From b5af548c1fc390ae00496e19ad7a91d308af9b12 Mon Sep 17 00:00:00 2001 From: Frank Spee Date: Thu, 19 Dec 2024 16:07:49 +0100 Subject: [PATCH 2/2] feat: add flag to disable `getSession` after signIn on local provider (#702) * feat: :sparkles: add flag to disable getSession after signIn on local provider * feat: :sparkles: add flag to disable getSession after signIn on refresh provider * docs: :sparkles: add flag to disable getSession after signIn on local/refresh provider * fix: :bug: sync refresh provider redirect external with local provider * refactor: :recycle: rename withGetSession boolean to withSession * docs: :memo: add example to disable getSession with signIn local provider * feat: :label: add withSession flag to SecondarySignInOptions interface * revert: style: :art: remove markdownlint md034 url change * docs: :memo: improve type documentation Co-authored-by: Marsel Shaikhin <18054980+phoenix-ru@users.noreply.github.com> * refactor: :recycle: rename withSession to callGetSession --------- Co-authored-by: Marsel Shaikhin <18054980+phoenix-ru@users.noreply.github.com> --- docs/guide/application-side/session-access.md | 4 ++++ src/runtime/composables/local/useAuth.ts | 7 +++++-- src/runtime/types.ts | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) 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 c24ac87b..c122262c 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 9b037855..e94c1707 100644 --- a/src/runtime/types.ts +++ b/src/runtime/types.ts @@ -574,6 +574,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 {