[FIX] Add token expired verification (#3964)

This commit is contained in:
Diego Mello 2022-04-06 17:35:53 -03:00 committed by GitHub
parent 2eba327396
commit 9a11fb2797
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 6 deletions

View File

@ -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<string, any>): ILoginFailure {
};
}
export function logout(forcedByServer = false): ILogout {
export function logout(forcedByServer = false, message = ''): ILogout {
return {
type: types.LOGOUT,
forcedByServer
forcedByServer,
message
};
}

View File

@ -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",

View File

@ -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 {