From 5b75851cca7cab7a8157fee82968c27480e67381 Mon Sep 17 00:00:00 2001 From: Putra Fajar H Date: Wed, 27 Dec 2023 16:16:10 +0700 Subject: [PATCH 1/2] fix: keepRequestedRoute --- src/runtime/composables/useSanctumAuth.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/runtime/composables/useSanctumAuth.ts b/src/runtime/composables/useSanctumAuth.ts index fc12ae2..9e1a585 100644 --- a/src/runtime/composables/useSanctumAuth.ts +++ b/src/runtime/composables/useSanctumAuth.ts @@ -58,16 +58,11 @@ export const useSanctumAuth = (): SanctumAuth => { await refreshIdentity(); - if (options.redirect.keepRequestedRoute) { - const route = useRoute(); - const requestedRoute = route.query.redirect as string | undefined; - - if (requestedRoute) { - await nuxtApp.runWithContext(() => navigateTo(requestedRoute)); - } - } - - if (options.redirect.onLogin) { + const route = useRoute(); + const requestedRoute = route.query.redirect as string | undefined; + if (options.redirect.keepRequestedRoute && requestedRoute) { + await nuxtApp.runWithContext(() => navigateTo(requestedRoute)); + } else if (options.redirect.onLogin) { const redirect = options.redirect.onLogin as string; await nuxtApp.runWithContext(() => navigateTo(redirect)); From bae128d2ed6c950216baa3d904763e8046fbd97d Mon Sep 17 00:00:00 2001 From: Putra Fajar H Date: Sun, 31 Dec 2023 03:12:39 +0700 Subject: [PATCH 2/2] resolve code review --- src/runtime/composables/useSanctumAuth.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/runtime/composables/useSanctumAuth.ts b/src/runtime/composables/useSanctumAuth.ts index 9e1a585..61d3d4a 100644 --- a/src/runtime/composables/useSanctumAuth.ts +++ b/src/runtime/composables/useSanctumAuth.ts @@ -58,13 +58,17 @@ export const useSanctumAuth = (): SanctumAuth => { await refreshIdentity(); - const route = useRoute(); - const requestedRoute = route.query.redirect as string | undefined; - if (options.redirect.keepRequestedRoute && requestedRoute) { - await nuxtApp.runWithContext(() => navigateTo(requestedRoute)); - } else if (options.redirect.onLogin) { - const redirect = options.redirect.onLogin as string; + if (options.redirect.keepRequestedRoute) { + const route = useRoute(); + const requestedRoute = route.query.redirect as string | undefined; + if (requestedRoute) { + await nuxtApp.runWithContext(() => navigateTo(requestedRoute)); + return; + } + } + if (options.redirect.onLogin) { + const redirect = options.redirect.onLogin as string; await nuxtApp.runWithContext(() => navigateTo(redirect)); } }