-
Any direction on how to incorporate passport js in express-zod-api? For google oauth2, I'm trying to do something like this. This is the callback/redirect uri endpoint in the oauth2 flow:
But it's getting stuck in the passport middleware, and doesn't do anything, neither does code execution get to the handler (on front end, it hangs on the part where user authorizes google sign in). |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hello @egithinji , could you please clarify: are you trying to integrate this solution: https://www.passportjs.org/packages/passport-google-oauth2/ ? |
Beta Was this translation helpful? Give feedback.
-
Passport is a great library with a perfect abstraction levels. It's a good choice. This is the actual function that https://github.com/jaredhanson/passport/blob/master/lib/middleware/authenticate.js#L70 They call it "middleware", however, it acts more like an endpoint handler, because in general scenario it does not call https://github.com/jaredhanson/passport/blob/master/lib/middleware/authenticate.js#L333 Since Long story short: Passport takes the complete control over authentication routes, it's a not something that expected to be ran in between. Therefore, instead of trying to fit it into https://github.com/RobinTail/express-zod-api#connect-to-your-own-express-app Thus, you:
This should work. I hope it will help you. |
Beta Was this translation helpful? Give feedback.
-
Thank you so much @RobinTail for taking your time to dig into this. Once I get a chance to try your solution I will get back to you on how it went. |
Beta Was this translation helpful? Give feedback.
@egithinji ,
Passport is a great library with a perfect abstraction levels. It's a good choice.
This is the actual function that
.authenticate()
creates:https://github.com/jaredhanson/passport/blob/master/lib/middleware/authenticate.js#L70
They call it "middleware", however, it acts more like an endpoint handler, because in general scenario it does not call
next()
.Instead, it calls
response.end()
:https://github.com/jaredhanson/passport/blob/master/lib/middleware/authenticate.js#L333
Since
next()
is not called, your handler is never called as well.Long story short: Passport takes the complete control over authentication routes, it's a not something that expected to be ran in between. T…