Requirements: write a middleware, used for user authentication, the function of middleware is to test whether JWT is empty, if overdue, whether been tampered with,
My question is: when first time log in res, the header in the custom of JWT (I named x - auth token), and how the JWT to the header of the req?
I am using jsonwebtoken NPM.
On the Internet to find a similar:
var response=the require ('/response ')
Var common=the require ("../common)
The module exports=function (the req, res, next) {
Var token=the req. Body. Token | | the req. Query. The token | | the req. Headers [' token ']
If (token) {
Common. Verifytoken (token). Then ((data)=& gt; {
If (data) {
The req. Decoded=data
Next ()
}
The else {
Res. The send (response. Out (" invalid token, please log in again "))
}
})
}
The else {
Res. The send (response. Err (" did not pass the token, please login first "))
}
}
Source: https://www.jianshu.com/p/9e76c01ebaf3
But look at line 5, the req. Body. The token is handed in how?
He just said, "put the data on the token, and returned to the user, the next time we need to verify the client take the need to bring a token value transfer,"
But how to "bring the need to bring a token value"?
The great god, please help!