async-labs / saas

Build your own SaaS business with SaaS boilerplate. Productive stack: React, Material-UI, Next, MobX, WebSockets, Express, Node, Mongoose, MongoDB. Written with TypeScript.
https://saas-app.async-await.com
MIT License
4.06k stars 675 forks source link

req.user inside Express route: undefined #128

Closed mrhanson3 closed 3 years ago

mrhanson3 commented 4 years ago

I keep getting this in the terminal that runs api. There are no issues in the app terminal. The code is the same code as the root folder here, I just added my own .env to api and app. Any thoughts about what I'm doing wrong?

tima101 commented 4 years ago

@mrhanson3 It does not mean something is wrong necessarily. If your user is logged-out then req.user can be undefined or null (depending on definition) on API server.

When your user is logged-in, passport or passwordless populate req.user with corresponding user object (created from corresponding MongoDB document).

mrhanson3 commented 4 years ago

But when I go to sign in through Google auth I get Forbidden on this page: http://localhost:8000/auth/google.

tima101 commented 3 years ago

@mrhanson3 Most likely reason is that you did not mount Express routes for Google OAuth in your Express server. Please provide link to the codebase that has this problem. Whenever there is a bug, please share code since I can't help without seeing it.

mrhanson3 commented 3 years ago

The codebase is copied from your code base. The only thing that isn't online are the envs. https://github.com/mrhanson3/saas-master6

tima101 commented 3 years ago

@mrhanson3 I took your codebase, installed packages and added my environmental variables. Google signup and login worked for me. It means the problem is with either the way you configured Google OAuth app at Google Cloud Platform and/or environmental variables.

mrhanson3 commented 3 years ago

This is embarrassing. It was an issue with my cut and paste job to my client ID. Sorry for bothering you with it.