-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(browser-extension): refactor middleware and remove unessential …
…endpoints
- Loading branch information
1 parent
7413074
commit 5774281
Showing
2 changed files
with
30 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
async function authentication(req, res, next) { | ||
if (req.path.startsWith("/auth/")) { | ||
next(); | ||
} else { | ||
if (!req.headers.authorization) { | ||
return res.status(403).json({ error: "No credentials sent!" }); | ||
} else { | ||
authorization = req.headers.authorization; | ||
token = authorization.split(" ")[1]; | ||
const result = await user.findOne({ | ||
where: { | ||
accessToken: token, | ||
}, | ||
}); | ||
if (result == null) { | ||
res.status(401).json({ error: "Unauthorized user" }); | ||
} else { | ||
req.user = result; | ||
next(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
authentication, | ||
}; |