-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[backend] Implement JWT authentication (#34)
* [backend] Implement JWT authentication * [backend] chore: Adding secret * [backend] chore: Adding secret * [backend] feat: User unit tests * [frontend] feat: Login functionality * [playwright] fix: Updating tests for login * [actions] chore: Update action for env file
- Loading branch information
1 parent
1e906b2
commit d2f69b3
Showing
30 changed files
with
1,178 additions
and
363 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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,20 @@ | ||
import jwt from "jsonwebtoken"; | ||
|
||
function authenticateToken(req, res, next) { | ||
const authHeader = req.headers["authorization"]; | ||
const token = authHeader && authHeader.split(" ")[1]; | ||
|
||
if (!token) { | ||
return res.status(401).send({ error: "unauthorized" }); | ||
} | ||
|
||
jwt.verify(token, process.env.JWT_SECRET, (err, user) => { | ||
if (err) { | ||
return res.status(403).send({ error: "forbidden" }); | ||
} | ||
req.user = user; | ||
next(); | ||
}); | ||
} | ||
|
||
export default authenticateToken; |
Oops, something went wrong.
d2f69b3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage for this commit
Coverage Report
d2f69b3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage for this commit
Coverage Report