April 2020
Intermediate to advanced
716 pages
18h 55m
English
The requireSignin method in auth.controller.js uses express-jwt to verify that the incoming request has a valid JWT in the Authorization header. If the token is valid, it appends the verified user's ID in an 'auth' key to the request object; otherwise, it throws an authentication error.
mern-skeleton/server/controllers/auth.controller.js:
const requireSignin = expressJwt({ secret: config.jwtSecret, userProperty: 'auth'})
We can add requireSignin to any route that should be protected against unauthenticated access.
Read now
Unlock full access