-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to display failure #76
Comments
All the strategies catch the errors your throw and wrap it in a Response. If you defined a If you didn't defined a And you can wrap the |
I don't get why but when I try using a try/catch block theres always an error thrown even when the credentials are correct. But when I remove the block it works how it is supposed to. Here's the action function I currently have: export const action: ActionFunction = async ({ request }) => {
try {
await authenticator.authenticate('local', request, {
successRedirect: '/'
})
} catch (e) {
if (e instanceof Response) {
const data = await e.json()
return { error: data.message }
}
throw e
}
return {}
} This works when the credentials are incorrect, but when they are correct, it throws: |
That’s because the library made use of Remix ability to throw responses including redirects |
Sound's interesting, do you have any suggestion on how I could fix it? |
Okay, I got it working like this: export const action: ActionFunction = async ({ request }) => {
try {
await authenticator.authenticate('local', request, {
successRedirect: '/'
})
} catch (e) {
console.log(e)
if (e instanceof Response && e.status === 401) {
const data = await e.json()
return {
error: data.message || 'Unauthorized'
}
}
throw e
}
return {}
} |
Hey,
I want to display the AuthenticationError that is thrown in the login function on the sign in page. Any suggestions on how I could do that or is this even possible?
Thanks
The text was updated successfully, but these errors were encountered: