-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.js
More file actions
33 lines (23 loc) · 685 Bytes
/
auth.js
File metadata and controls
33 lines (23 loc) · 685 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const jwt = require("jsonwebtoken")
const SECRET_KEY = "NOTESAPI"
const auth =(req,res,next)=>{
try {
let token = req.headers.authorization
console.log(token+ "me")
if(token){
token = token.split(" ")[1];
let user = jwt.verify(token,SECRET_KEY)
req.userId = user.id
console.log(user.id);
}
else{
return res.status(401).json({
message:"unotherized user"
})
}
next();
} catch (err) {
console.log(err);
}
}
module.exports = auth;