Requiring sign-in

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.

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.