Created
November 25, 2017 15:47
-
-
Save giladno/820d61745568976f17d2d236b78a1dc3 to your computer and use it in GitHub Desktop.
user auth in express
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.use(async (req, res, next)=>{ | |
| try { | |
| req.user = await auth.validate(req); | |
| } catch(err) { | |
| if (...) | |
| return res.json({error: 'user not found'}); | |
| next(err); | |
| } | |
| }); | |
| app.get('/test', (req, res)=>{ | |
| res.json(req.user); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment