February 2019
Intermediate to advanced
204 pages
4h 52m
English
A part of authorization is handled by injecting the user information. We need an endpoint that verifies whether a user is valid. To define /api/user/auth endpoint, follow these steps:
routerAuth.get('/users/auth', User.auth);
auth: (req, res) => { if (!req.user) { handleFailure(res, { status: 401 }); } else { Model.users .authUser(req.user.id) .then(user => handleSuccess(res, { user })) .catch(errors => handleFailure(res, { errors, message: errors.message, status: 401 }), ); } },
Schema.statics.authUser = function(id) { return new Promise((resolve, ...Read now
Unlock full access