feat: enforce concurrent session limit with login picker (CW-7169) (#14621)

## Description

Cap active sessions at `MAX_USER_SESSIONS` which defaults to existing
value of `25` per user. This ensure existing user login behavior is not
affected for self-hosted installations. Browser users at the cap see a
session picker (409 response) to choose which session to end.
Non-browser clients and partially-tracked users get silent
oldest-session eviction.

Depends on #14556.

## Type of change

- [x] New feature (non-breaking change which adds functionality)

## How Has This Been Tested?

Specs cover: under limit, at limit (browser picker, non-browser
eviction), partial tracking fallback, revoke single/all sessions during
login, session row creation on successful login.

---------

Co-authored-by: Sony Mathew <sony@chatwoot.com>
This commit is contained in:
Vishnu Narayanan
2026-06-15 17:28:13 +05:30
committed by GitHub
co-authored by Sony Mathew
parent ba0ba46c9c
commit 396631ad7d
8 changed files with 476 additions and 3 deletions
+9
View File
@@ -43,6 +43,15 @@ export const login = async ({
mfaToken: error.response.data.mfa_token,
};
}
if (
error.response?.status === 409 &&
error.response?.data?.sessions_limit_reached
) {
return {
sessionsLimitReached: true,
sessions: error.response.data.sessions,
};
}
const loginError = new Error(parseAPIErrorResponse(error));
loginError.errorCode = error.response?.data?.error_code;
throw loginError;
+71 -1
View File
@@ -8,6 +8,8 @@ import { useVuelidate } from '@vuelidate/core';
import { SESSION_STORAGE_KEYS } from 'dashboard/constants/sessionStorage';
import SessionStorage from 'shared/helpers/sessionStorage';
import { useBranding } from 'shared/composables/useBranding';
import AnalyticsHelper from 'dashboard/helper/AnalyticsHelper';
import { SESSION_EVENTS } from 'dashboard/helper/AnalyticsHelper/events';
// components
import SimpleDivider from '../../components/Divider/SimpleDivider.vue';
@@ -17,6 +19,7 @@ import Spinner from 'shared/components/Spinner.vue';
import Icon from 'dashboard/components-next/icon/Icon.vue';
import NextButton from 'dashboard/components-next/button/Button.vue';
import MfaVerification from 'dashboard/components/auth/MfaVerification.vue';
import SessionLimitOverlay from 'dashboard/components/auth/SessionLimitOverlay.vue';
const ERROR_MESSAGES = {
'no-account-found': 'LOGIN.OAUTH.NO_ACCOUNT_FOUND',
@@ -36,6 +39,7 @@ export default {
NextButton,
SimpleDivider,
MfaVerification,
SessionLimitOverlay,
Icon,
},
props: {
@@ -68,6 +72,8 @@ export default {
error: '',
mfaRequired: false,
mfaToken: null,
sessionsLimitReached: false,
limitedSessions: [],
};
},
validations() {
@@ -182,6 +188,15 @@ export default {
return;
}
// Check if sessions limit reached
if (result?.sessionsLimitReached) {
this.loginApi.showLoading = false;
this.sessionsLimitReached = true;
this.limitedSessions = result.sessions;
AnalyticsHelper.track(SESSION_EVENTS.LIMIT_HIT);
return;
}
this.handleImpersonation();
this.showAlertMessage(this.$t('LOGIN.API.SUCCESS_MESSAGE'));
})
@@ -224,6 +239,51 @@ export default {
this.mfaToken = null;
this.credentials.password = '';
},
retryLoginWithParams(extraParams) {
const credentials = {
email: this.email
? decodeURIComponent(this.email)
: this.credentials.email,
password: this.credentials.password,
sso_auth_token: this.ssoAuthToken,
ssoAccountId: this.ssoAccountId,
ssoConversationId: this.ssoConversationId,
...extraParams,
};
this.sessionsLimitReached = false;
this.limitedSessions = [];
this.loginApi.showLoading = true;
login(credentials)
.then(result => {
if (result?.sessionsLimitReached) {
this.loginApi.showLoading = false;
this.sessionsLimitReached = true;
this.limitedSessions = result.sessions;
AnalyticsHelper.track(SESSION_EVENTS.LIMIT_HIT);
return;
}
this.handleImpersonation();
this.showAlertMessage(this.$t('LOGIN.API.SUCCESS_MESSAGE'));
})
.catch(response => {
this.loginApi.hasErrored = true;
this.showAlertMessage(
response?.message || this.$t('LOGIN.API.UNAUTH')
);
});
},
handleSessionRevoke(sessionId) {
this.retryLoginWithParams({ revoke_session_id: sessionId });
},
handleSessionRevokeAll() {
this.retryLoginWithParams({ revoke_all_sessions: true });
},
handleSessionLimitCancel() {
this.sessionsLimitReached = false;
this.limitedSessions = [];
this.credentials.password = '';
},
},
};
</script>
@@ -255,8 +315,18 @@ export default {
</p>
</section>
<!-- Session Limit Section -->
<section v-if="sessionsLimitReached" class="mt-11">
<SessionLimitOverlay
:sessions="limitedSessions"
@revoke="handleSessionRevoke"
@revoke-all="handleSessionRevokeAll"
@cancel="handleSessionLimitCancel"
/>
</section>
<!-- MFA Verification Section -->
<section v-if="mfaRequired" class="mt-11">
<section v-else-if="mfaRequired" class="mt-11">
<MfaVerification
:mfa-token="mfaToken"
@verified="handleMfaVerified"