Skip to content

Instantly share code, notes, and snippets.

@shinecita
Created February 20, 2024 20:10
Show Gist options
  • Save shinecita/3dbffaf861ab9306d5caab543521ea43 to your computer and use it in GitHub Desktop.
Save shinecita/3dbffaf861ab9306d5caab543521ea43 to your computer and use it in GitHub Desktop.
Authorization middleware
function isAuthorized(req, res, next) {
if (req.headers.authorization) {
// compare access token with db
if (everythingok)
RETURN next()
}
if (!req.user) {
res.status(401).json({error: reason})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment