Skip to content

Is it valid to throw a redirect inside of the authentication function? #161

Answered by sergiodxa
vedantroy asked this question in Q&A
Discussion options

You must be logged in to vote

Any error throw from the verify callback (the callback of the strategies) is caught by the Authenticator, then if you set failureRedirect when calling authenticator.authenticate then the library will get the error.message and set it on the session before doing a redirect.

Usually that should be enough, so you could setup any redirect using that option. But if you want to redirect directly from verify callback you could don't pass failureRedirect and instead pass the throwOnError option which will re-throw the error from the verify callback which will let you throw redirects.

That said, I don't recommend you to throw redirects from the verify callback, that will mix your business logic of …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@vedantroy
Comment options

@sergiodxa
Comment options

Answer selected by sergiodxa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants