ejs jwt authentication code example
Example: ejs jwt authentication
const cookieParser = require('cookie-parser')
const withAuthUserId = [
cookieParser(),
(req, res, next) => {
const claims = jsonwebtoken.verify(req.cookies['jwt'], jwtKey)
req['authUserId'] = claims['sub']
next()
}
]
app.get('/api/auth-user', ...withAuthUserId, (req, res) => {
/* See: req['authUserId'] */
})