diff --git a/app/actions/login.ts b/app/actions/login.ts index 02d280747..990c9f858 100644 --- a/app/actions/login.ts +++ b/app/actions/login.ts @@ -25,6 +25,7 @@ interface ILoginFailure extends Action { interface ILogout extends Action { forcedByServer: boolean; + message: string; } interface ISetUser extends Action { @@ -79,10 +80,11 @@ export function loginFailure(err: Record): ILoginFailure { }; } -export function logout(forcedByServer = false): ILogout { +export function logout(forcedByServer = false, message = ''): ILogout { return { type: types.LOGOUT, - forcedByServer + forcedByServer, + message }; } diff --git a/app/i18n/locales/en.json b/app/i18n/locales/en.json index fe16b8854..2f416a609 100644 --- a/app/i18n/locales/en.json +++ b/app/i18n/locales/en.json @@ -597,6 +597,7 @@ "you": "you", "You": "You", "Logged_out_by_server": "You've been logged out by the server. Please log in again.", + "Token_expired": "Your session has expired. Please log in again.", "You_need_to_access_at_least_one_RocketChat_server_to_share_something": "You need to access at least one Rocket.Chat server to share something.", "You_need_to_verifiy_your_email_address_to_get_notications": "You need to verify your email address to get notifications", "Your_certificate": "Your Certificate", diff --git a/app/sagas/login.js b/app/sagas/login.js index 41fe6c5ca..6b265f32c 100644 --- a/app/sagas/login.js +++ b/app/sagas/login.js @@ -65,8 +65,10 @@ const handleLoginRequest = function* handleLoginRequest({ credentials, logoutOnE yield put(loginSuccess(result)); } } catch (e) { - if (logoutOnError && e.data && e.data.message && /you've been logged out by the server/i.test(e.data.message)) { - yield put(logout(true)); + if (e?.data?.message && /you've been logged out by the server/i.test(e.data.message)) { + yield put(logout(true, 'Logged_out_by_server')); + } else if (e?.data?.message && /your session has expired/i.test(e.data.message)) { + yield put(logout(true, 'Token_expired')); } else { logEvent(events.LOGIN_DEFAULT_LOGIN_F); yield put(loginFailure(e)); @@ -177,7 +179,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) { } }; -const handleLogout = function* handleLogout({ forcedByServer }) { +const handleLogout = function* handleLogout({ forcedByServer, message }) { yield put(encryptionStop()); yield put(appStart({ root: RootEnum.ROOT_LOADING, text: I18n.t('Logging_out') })); const server = yield select(getServer); @@ -188,7 +190,9 @@ const handleLogout = function* handleLogout({ forcedByServer }) { // if the user was logged out by the server if (forcedByServer) { yield put(appStart({ root: RootEnum.ROOT_OUTSIDE })); - showErrorAlert(I18n.t('Logged_out_by_server'), I18n.t('Oops')); + if (message) { + showErrorAlert(I18n.t(message), I18n.t('Oops')); + } yield delay(300); EventEmitter.emit('NewServer', { server }); } else {