Add logout all devices button and extend auth logout endpoint

This commit is contained in:
advplyr 2026-07-24 17:44:03 -05:00
parent dc0b24a03f
commit e56c1099e6
4 changed files with 39 additions and 7 deletions

View file

@ -471,18 +471,23 @@ class Auth {
res.json(openIdIssuerConfig)
})
// Logout route
/**
* Logout route
* Use ?allDevices=1 to destroy every session for this user instead of just the current one
*/
router.post('/logout', async (req, res) => {
// Refresh token be alternatively be sent in the header
const refreshToken = req.cookies.refresh_token || req.headers['x-refresh-token']
const allDevices = req.query.allDevices === '1'
// Clear refresh token cookie
res.clearCookie('refresh_token', {
path: '/'
})
// Invalidate the session in database using refresh token
if (refreshToken) {
if (allDevices) {
await this.tokenManager.invalidateAllSessionsForRefreshToken(refreshToken)
} else if (refreshToken) {
await this.tokenManager.invalidateRefreshToken(refreshToken)
} else {
Logger.info(`[Auth] logout: No refresh token on request`)