Repository navigation
How to pass redirectTo to the Auth0 callback loader #82
Answered
by
danestves
piotrkulpinski
asked this question in
Q&A
|
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 |
Answered by
danestves
Nov 22, 2022
Replies: 1 comment
|
Hi @piotrkulpinski to be able to have a |
0 replies
Answer selected by
danestves
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @piotrkulpinski to be able to have a
redirectTobehavior, please follow this guide from Sergio https://sergiodxa.com/articles/add-returnto-behavior-to-remix-auth