Skip to content

Commit 552ae15

Browse files
committed
fixing the token issue in model file
1 parent b6935a5 commit 552ae15

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/middleware/auth.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ const auth = async (req, res, next)=>{
55
// console.log("auth middleware")
66
// next()
77
try{
8+
console.log('inside auth')
89
const token = req.header('Authorization').replace('Bearer ', '')
10+
console.log(token)
11+
console.log(process.env.JWT_SECRET)
912
const decoded = jwt.verify(token, process.env.JWT_SECRET)
13+
14+
console.log(decoded)
15+
console.log('test')
1016
const user = await User.findById({_id: decoded._id, 'tokens.token': token})
17+
1118
// const tokenExp = decoded.exp
1219
// const date=Math.round(new Date().getTime()/1000 )
1320
// const currentSystemDate = new Date().toLocaleString()

src/models/users.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ userSchema.methods.generateAuthToken = async function(){
8282
const user = this;
8383
//token expires in 7 seconds
8484
//const token = jwt.sign({_id:user._id.toString()},'thisismynewcourse',{expiresIn:'7 seconds'})
85-
const token = jwt.sign({_id:user._id.toString()},'thisismynewcourse',{expiresIn:'10 hours'})
85+
const token = jwt.sign({_id:user._id.toString()},process.env.JWT_SECRET,{expiresIn:'10 hours'})
8686
user.tokens = user.tokens.concat({token})
8787
await user.save()
8888
return token

0 commit comments

Comments
 (0)