How to pass redirectTo to the Auth0 callback loader #82
-
Hi, I tried setting a cookie in Login page loader but it's not being set due to the throw in the authenticator. Here's what I have: // app/routes/auth/login.tsx
export const loader = async ({ request }: LoaderArgs) => {
const session = await getSession(request.headers.get('cookie'))
const url = new URL(request.url)
const redirectTo = url.searchParams.get('redirectTo') || '/'
session.set('redirectTo', redirectTo)
// This will throw a redirect so the cookie is never set
await authenticator.authenticate('auth0', request)
return json(null, {
headers: {
'Set-Cookie': await commitSession(session),
},
})
} // app/routes/auth/callback.tsx
export const loader = async ({ request }: LoaderArgs) => {
const session = await getSession(request.headers.get('cookie'))
const redirectTo = session.get('redirectTo') || '/'
return await authenticator.authenticate('auth0', request, {
successRedirect: redirectTo,
failureRedirect: '/',
})
} Is there any other way to pass a redirect value from login to callback loader? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @piotrkulpinski to be able to have a |
Beta Was this translation helpful? Give feedback.
Hi @piotrkulpinski to be able to have a
redirectTo
behavior, please follow this guide from Sergio https://sergiodxa.com/articles/add-returnto-behavior-to-remix-auth