From 8c73bf3d51bd26cf211aac6f331fcf548cffc411 Mon Sep 17 00:00:00 2001 From: Maxime Riehl Date: Wed, 18 Sep 2024 19:12:44 +0200 Subject: [PATCH 1/2] docs: laravel-passport.md fix "Learn more" issue link (#909) --- docs/recipes/community/laravel-passport.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/recipes/community/laravel-passport.md b/docs/recipes/community/laravel-passport.md index d69e69e7..f52f5276 100644 --- a/docs/recipes/community/laravel-passport.md +++ b/docs/recipes/community/laravel-passport.md @@ -111,5 +111,5 @@ export default NuxtAuthHandler({ ``` :::tip Learn more -You can find the full discussion in the issue [#149](https://github.com/sidebase/nuxt-auth/v0.6/issues/149). Solution provided by [@Jericho1060](https://github.com/Jericho1060) +You can find the full discussion in the issue [#149](https://github.com/sidebase/nuxt-auth/issues/149). Solution provided by [@Jericho1060](https://github.com/Jericho1060) ::: From 5276a97997e4d1d5d3f0b76c0b064c0ab86e92cd Mon Sep 17 00:00:00 2001 From: andychukse Date: Thu, 19 Sep 2024 12:27:51 +0100 Subject: [PATCH 2/2] enh(#861): Redirect back to requested page after authentication (#870) * merge with main * added check for presence of addDefaultCallbackUrl in globalAppMiddleware * Update src/runtime/composables/local/useAuth.ts * Update useAuth.ts --------- Co-authored-by: Zoey Co-authored-by: Marsel Shayhin <18054980+phoenix-ru@users.noreply.github.com> --- src/runtime/composables/local/useAuth.ts | 10 ++++++++-- src/runtime/middleware/auth.ts | 13 +++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/runtime/composables/local/useAuth.ts b/src/runtime/composables/local/useAuth.ts index 1368fe0d..cd4ff21c 100644 --- a/src/runtime/composables/local/useAuth.ts +++ b/src/runtime/composables/local/useAuth.ts @@ -10,7 +10,7 @@ import { type UseAuthStateReturn, useAuthState } from './useAuthState' import { callWithNuxt } from '#app/nuxt' // @ts-expect-error - #auth not defined import type { SessionData } from '#auth' -import { navigateTo, nextTick, useNuxtApp, useRuntimeConfig } from '#imports' +import { navigateTo, nextTick, useNuxtApp, useRoute, useRuntimeConfig } from '#imports' type Credentials = { username?: string, email?: string, password?: string } & Record @@ -60,7 +60,13 @@ const signIn: SignInFunc = async (credentials, signInOptions, const { redirect = true, external } = signInOptions ?? {} let { callbackUrl } = signInOptions ?? {} if (typeof callbackUrl === 'undefined') { - callbackUrl = await determineCallbackUrl(runtimeConfig.public.auth, () => getRequestURLWN(nuxt)) + const redirectQueryParam = useRoute()?.query?.redirect + if (redirectQueryParam) { + callbackUrl = redirectQueryParam.toString() + } + else { + callbackUrl = await determineCallbackUrl(runtimeConfig.public.auth, () => getRequestURLWN(nuxt)) + } } if (redirect) { return navigateTo(callbackUrl, { external }) diff --git a/src/runtime/middleware/auth.ts b/src/runtime/middleware/auth.ts index 4f32140d..333d35aa 100644 --- a/src/runtime/middleware/auth.ts +++ b/src/runtime/middleware/auth.ts @@ -105,6 +105,19 @@ export default defineNuxtRouteMiddleware((to) => { return navigateTo(metaAuth.navigateUnauthenticatedTo) } else { + if (typeof globalAppMiddleware === 'object' && globalAppMiddleware.addDefaultCallbackUrl) { + let redirectUrl: string = to.fullPath + if (typeof globalAppMiddleware.addDefaultCallbackUrl === 'string') { + redirectUrl = globalAppMiddleware.addDefaultCallbackUrl + } + + return navigateTo({ + path: authConfig.provider.pages.login, + query: { + redirect: redirectUrl + } + }) + } return navigateTo(authConfig.provider.pages.login) } })