Skip to content

Instantly share code, notes, and snippets.

@giladno
Created November 25, 2017 15:47
Show Gist options
  • Save giladno/820d61745568976f17d2d236b78a1dc3 to your computer and use it in GitHub Desktop.
Save giladno/820d61745568976f17d2d236b78a1dc3 to your computer and use it in GitHub Desktop.
user auth in express
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