-
-
Notifications
You must be signed in to change notification settings - Fork 153
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
ERR_HTTP_HEADERS_SENT Error in Passport Google OAuth 2.0 Authentication #94
Comments
The issue is likely occurring because you are calling res.redirect() directly within the Passport authenticate callback function. This will cause headers to be sent twice - once from the redirect and once from the original request handler. A few ways to fix:
Then in your request handler:
Then handle the redirect there if needed. Let me know if any of those suggestions help resolve it! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue: ERR_HTTP_HEADERS_SENT Error in Passport Google OAuth 2.0 Authentication
Expected behavior
Upon successful authentication using Google OAuth 2.0 with Passport, I expect the user to be redirected to a successful login route.
Actual behavior
I'm getting the
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
when trying to redirect after successful authentication using Google OAuth 2.0 with Passport. The error seems to originate fromresponse.redirect
within thehandleAuthenticationWithGoogleSuccess
function.Steps to reproduce
Here are the main snippets from my code that relate to this issue:
Passport Service
Google Strategy
Controller
server.ts
Environment
I'm unable to pinpoint the reason why this error occurs. I'm looking for any advice on how to troubleshoot or fix this issue. Thanks for any help or suggestions!
The text was updated successfully, but these errors were encountered: