davellanedam / node-express-mongodb-jwt-rest-api-skeleton

This is a basic API REST skeleton written on JavaScript using async/await. Great for building a starter web API for your front-end (Android, iOS, Vue, react, angular, or anything that can consume an API). Demo of frontend in VueJS here: https://github.com/davellanedam/vue-skeleton-mvp
MIT License
904 stars 286 forks source link

Best way to check logged in user from another service? #226

Closed squidis closed 3 years ago

squidis commented 3 years ago

Thanks for maintaining what looks like a great authentication api. I'm trying to setup a user service that my other api's can pass a JWT to to check if a user is authenticated. As this package uses a blocklist am I right in thinking that I need to call this central service as opposed to decrypting the JWT to get the user ID?

Would it be a case of adding a new route like the refresh token route, something like this? router.get( '/whoami', requireAuth, roleAuthorization(['user', 'admin']), trimRequest.all )

davellanedam commented 3 years ago

Hey @squidis! Thank you, yeah, you can do that as well.