Skip to content

Commit

Permalink
Revoke other sessions when password is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed May 14, 2024
1 parent 923d587 commit 0b093dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ module.exports = {
const svc_email = req.services.get('email');
svc_email.send_email({ email: req.user.email }, 'password_change_notification');

// Kick out all other sessions
const svc_auth = req.services.get('auth');
const sessions = await svc_auth.list_sessions(req.actor);
for ( const session of sessions ) {
if ( session.current ) continue;
await svc_auth.revoke_session(req.actor, session.uuid);
}

return res.send('Password successfully updated.')
}
};
7 changes: 5 additions & 2 deletions packages/backend/src/services/auth/AuthService.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,14 @@ class AuthService extends BaseService {
mysql: () => session.meta,
otherwise: () => JSON.parse(session.meta ?? "{}")
})();
sessions.push(session);
};

for ( const session of sessions ) {
if ( session.uuid === actor.type.session ) {
session.current = true;
}
sessions.push(session);
};
}

return sessions;
}
Expand Down

0 comments on commit 0b093dd

Please sign in to comment.