Skip to content
9 changes: 7 additions & 2 deletions src/runtime/composables/local/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>

Expand Down Expand Up @@ -60,7 +60,12 @@ 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))
if (useRoute()?.query?.redirect) {
callbackUrl = useRoute().query.redirect?.toString()
Comment thread
phoenix-ru marked this conversation as resolved.
Outdated
}
else {
callbackUrl = await determineCallbackUrl(runtimeConfig.public.auth, () => getRequestURLWN(nuxt))
}
}
if (redirect) {
return navigateTo(callbackUrl, { external })
Expand Down
7 changes: 6 additions & 1 deletion src/runtime/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ export default defineNuxtRouteMiddleware((to) => {
return navigateTo(metaAuth.navigateUnauthenticatedTo)
}
else {
return navigateTo(authConfig.provider.pages.login)
return navigateTo({
path: authConfig.provider.pages.login,
query: {
redirect: to.fullPath
Comment thread
andychukse marked this conversation as resolved.
Outdated
}
})
}
})