always call the rest logout command, don't vomit on the error

This commit is contained in:
Wyatt Johnson
2018-05-31 14:56:18 -06:00
parent 01a0d0d587
commit 66f2d41033
2 changed files with 11 additions and 10 deletions
+6 -5
View File
@@ -96,13 +96,14 @@ export const logout = () => async (
_,
{ rest, client, pym, localStorage }
) => {
// Stop if the token doen't exist
if (!localStorage.getItem('token')) {
return;
try {
await rest('/auth', { method: 'DELETE' });
} catch (err) {
// We ignore any REST related errors from the delete action, which may/may
// not have had a cookie/token attached to it. The logout action was still
// called, so we still want to cleanup.
}
await rest('/auth', { method: 'DELETE' });
// Clear the auth data persisted to localStorage.
cleanAuthData(localStorage);
+5 -5
View File
@@ -40,15 +40,15 @@ authorization.has = (user, ...roles) => {
* @return {Callback} connect middleware
*/
authorization.needed = (...roles) => [
// Insert the pre-needed middlware.
// Insert the pre-needed middleware.
...authorization.middleware,
// Insert the actual middleware to check for the required role.
(req, res, next) => {
// All routes that are wrapepd with this middleware actually require a role.
// All routes that are wrapped with this middleware actually require a role.
if (!req.user) {
debug(`No user on request, returning with ${ErrNotAuthorized}`);
return next(ErrNotAuthorized);
debug(`No user on request, returning with ErrNotAuthorized`);
return next(new ErrNotAuthorized());
}
// Check to see if the current user has all the roles requested for the given
@@ -56,7 +56,7 @@ authorization.needed = (...roles) => [
// evaluate to true.
if (!authorization.has(req.user, ...roles)) {
debug('User does not have all the required roles to access this page');
return next(ErrNotAuthorized);
return next(new ErrNotAuthorized());
}
// Looks like they're allowed!