Skip to content

Commit

Permalink
Merge branch 'main' into enh/843-signup-flow-enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
iamKiNG-Fr authored Sep 19, 2024
2 parents e5373a4 + 5276a97 commit 6ee85a0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/recipes/community/laravel-passport.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
:::
10 changes: 8 additions & 2 deletions src/runtime/composables/local/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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<string, any>

Expand Down Expand Up @@ -59,7 +59,13 @@ const signIn: SignInFunc<Credentials, any> = 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 })
Expand Down
13 changes: 13 additions & 0 deletions src/runtime/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})

0 comments on commit 6ee85a0

Please sign in to comment.