From 5e3f36f3c5b48bbe4caea6823cb2a427fef311c7 Mon Sep 17 00:00:00 2001 From: Zoey Kaiser Date: Wed, 11 Oct 2023 18:40:59 +0200 Subject: [PATCH 1/4] added check to ensure login page does not get blocked by middleware --- src/runtime/middleware/auth.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/runtime/middleware/auth.ts b/src/runtime/middleware/auth.ts index 9eda419d..04b5dd07 100644 --- a/src/runtime/middleware/auth.ts +++ b/src/runtime/middleware/auth.ts @@ -61,6 +61,14 @@ export default defineNuxtRouteMiddleware((to) => { return } + // We do not want to block the login page when the local provider is used + if (authConfig.provider?.type === 'local') { + const loginRoute: string | null = authConfig.provider?.pages?.login + if (loginRoute && loginRoute === to.path) { + return + } + } + /** * We do not want to enforce protection on `404` pages (unless the user opts out of it by setting `allow404WithoutAuth: false`). * From 4bf44070edef4682fae358a1b3ef446293d1c7e7 Mon Sep 17 00:00:00 2001 From: Zoey Date: Mon, 16 Oct 2023 17:47:30 +0200 Subject: [PATCH 2/4] Update 4.protecting-pages.md --- docs/content/v0.6/3.application-side/4.protecting-pages.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/v0.6/3.application-side/4.protecting-pages.md b/docs/content/v0.6/3.application-side/4.protecting-pages.md index c5d28644..750f40cd 100644 --- a/docs/content/v0.6/3.application-side/4.protecting-pages.md +++ b/docs/content/v0.6/3.application-side/4.protecting-pages.md @@ -16,7 +16,7 @@ export default defineNuxtConfig({ }) ``` -Now *all pages* will require sign-in. Learn how to add excepted pages [below](/nuxt-auth/v0.6/application-side/protecting-pages#disabling-the-global-middleware-locally) +Now *all pages*, aside from the login pages will require sign-in. Learn how to add excepted pages [below](/nuxt-auth/v0.6/application-side/protecting-pages#disabling-the-global-middleware-locally) To enable page-local protection (2), add the following `definePageMeta` directive to a page: ```vue From 866319db4941df54333506bd29a5c632f0f9f5af Mon Sep 17 00:00:00 2001 From: Zoey Date: Mon, 16 Oct 2023 17:48:20 +0200 Subject: [PATCH 3/4] Update 2.nuxt-config.md --- docs/content/v0.6/2.configuration/2.nuxt-config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/v0.6/2.configuration/2.nuxt-config.md b/docs/content/v0.6/2.configuration/2.nuxt-config.md index a2bae96e..34144b5a 100644 --- a/docs/content/v0.6/2.configuration/2.nuxt-config.md +++ b/docs/content/v0.6/2.configuration/2.nuxt-config.md @@ -132,7 +132,7 @@ type ProviderLocal = { */ endpoints?: { /** - * What method and path to call to perform the sign-in. This endpoint must return a token that can be used to authenticate subsequent requests. + * What method and path to call to perform the sign-in. This endpoint must return a token that can be used to authenticate subsequent requests. This page will also not be blocked by the global middleware. * * @default { path: '/login', method: 'post' } */ From ab55dd8c4b953ea98151f46c81f27f28cfcb8642 Mon Sep 17 00:00:00 2001 From: Zoey Date: Mon, 16 Oct 2023 17:58:42 +0200 Subject: [PATCH 4/4] Update 2.nuxt-config.md --- docs/content/v0.6/2.configuration/2.nuxt-config.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content/v0.6/2.configuration/2.nuxt-config.md b/docs/content/v0.6/2.configuration/2.nuxt-config.md index 53eea6a4..242b26ac 100644 --- a/docs/content/v0.6/2.configuration/2.nuxt-config.md +++ b/docs/content/v0.6/2.configuration/2.nuxt-config.md @@ -132,7 +132,7 @@ type ProviderLocal = { */ endpoints?: { /** - * What method and path to call to perform the sign-in. This endpoint must return a token that can be used to authenticate subsequent requests. This page will also not be blocked by the global middleware. + * What method and path to call to perform the sign-in. This endpoint must return a token that can be used to authenticate subsequent requests. * * @default { path: '/login', method: 'post' } */ @@ -164,7 +164,7 @@ type ProviderLocal = { */ pages?: { /** - * Path of the login-page that the user should be redirected to, when they try to access a protected page without being logged in. + * Path of the login-page that the user should be redirected to, when they try to access a protected page without being logged in. This page will also not be blocked by the global middleware. * * @default '/login' */