From 64e90012c4cd9dc08af3ef1ccca50a2c521b5b68 Mon Sep 17 00:00:00 2001 From: Anja Rupnik <31987405+anjarupnik@users.noreply.github.com> Date: Thu, 16 Nov 2023 16:48:53 +0100 Subject: [PATCH] feat: add possibility to disable signOut endpoint for local provider (#572) --- docs/content/2.configuration/2.nuxt-config.md | 4 ++-- src/runtime/composables/local/useAuth.ts | 8 ++++++-- src/runtime/types.ts | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/content/2.configuration/2.nuxt-config.md b/docs/content/2.configuration/2.nuxt-config.md index 242b26ac..d79cba6d 100644 --- a/docs/content/2.configuration/2.nuxt-config.md +++ b/docs/content/2.configuration/2.nuxt-config.md @@ -138,11 +138,11 @@ type ProviderLocal = { */ signIn?: { path?: string, method?: RouterMethod }, /** - * What method and path to call to perform the sign-out. + * What method and path to call to perform the sign-out. Set to false to disable. * * @default { path: '/logout', method: 'post' } */ - signOut?: { path?: string, method?: RouterMethod }, + signOut?: { path?: string, method?: RouterMethod } | false, /** * What method and path to call to perform the sign-up. * diff --git a/src/runtime/composables/local/useAuth.ts b/src/runtime/composables/local/useAuth.ts index ecf49286..e01bd740 100644 --- a/src/runtime/composables/local/useAuth.ts +++ b/src/runtime/composables/local/useAuth.ts @@ -53,9 +53,13 @@ const signOut: SignOutFunc = async (signOutOptions) => { data.value = null rawToken.value = null - const { path, method } = config.endpoints.signOut + const signOutConfig = config.endpoints.signOut + let res - const res = await _fetch(nuxt, path, { method, headers }) + if (signOutConfig) { + const { path, method } = signOutConfig + res = await _fetch(nuxt, path, { method, headers }) + } const { callbackUrl, redirect = true, external } = signOutOptions ?? {} if (redirect) { diff --git a/src/runtime/types.ts b/src/runtime/types.ts index 3563f6de..4b986bda 100644 --- a/src/runtime/types.ts +++ b/src/runtime/types.ts @@ -74,11 +74,11 @@ type ProviderLocal = { */ signIn?: { path?: string, method?: RouterMethod }, /** - * What method and path to call to perform the sign-out. + * What method and path to call to perform the sign-out. Set to false to disable. * * @default { path: '/logout', method: 'post' } */ - signOut?: { path?: string, method?: RouterMethod }, + signOut?: { path?: string, method?: RouterMethod } | false, /** * What method and path to call to perform the sign-up. *