-
-
Notifications
You must be signed in to change notification settings - Fork 68
Token security #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Token security #10
Changes from all commits
392a3fb
62720dc
130075c
30145da
c2b2dfc
1c60887
7216de8
fa8f67f
42ad3a6
ed38442
1b82074
0fb0b1e
3a160f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| const { Magic } = require("@magic-sdk/admin"); | ||
| const magic = new Magic(process.env.MAGIC_SECRET_KEY); | ||
|
|
||
| const authenticate = async (req, res, next) => { | ||
| console.log("Auth middleware 2 called"); | ||
| try { | ||
| const { didToken } = req.cookies; | ||
| await magic.token.validate(didToken); | ||
| next(); | ||
| } catch (error) { | ||
| return res.status(401).json({ error: error.message }); | ||
| } | ||
| }; | ||
|
|
||
| module.exports = authenticate; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ router.post('/api/user/create', authMiddleware, async (req, res, next) => { | |
| const magic_id = req.body.magic_id; | ||
| const user_name = req.body.user_name; | ||
| const email = req.body.email; | ||
| const didToken = req.headers.authorization.substring(7); | ||
|
|
||
| if (!user_name || !magic_id || !email) { | ||
| return next( new AppError("Missing required fields", 400)); | ||
|
|
@@ -43,6 +44,7 @@ router.post('/api/user/create', authMiddleware, async (req, res, next) => { | |
| }) | ||
| console.log("saving user") | ||
| await user.save(); | ||
| res.cookie('didToken',didToken,{httpOnly:true}) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explain this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remember I commented the |
||
| return res.status(200).json({ message: "User created successfully" }); | ||
| } | ||
| else { | ||
|
|
||
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.
Can you explain this?
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.
mentioning
withCredentials:truewill ensure that the cookies are sent to the server with every request.