[FIX] Add token expired verification (#3964)
This commit is contained in:
parent
2eba327396
commit
9a11fb2797
|
@ -25,6 +25,7 @@ interface ILoginFailure extends Action {
|
||||||
|
|
||||||
interface ILogout extends Action {
|
interface ILogout extends Action {
|
||||||
forcedByServer: boolean;
|
forcedByServer: boolean;
|
||||||
|
message: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ISetUser extends Action {
|
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 {
|
return {
|
||||||
type: types.LOGOUT,
|
type: types.LOGOUT,
|
||||||
forcedByServer
|
forcedByServer,
|
||||||
|
message
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -597,6 +597,7 @@
|
||||||
"you": "you",
|
"you": "you",
|
||||||
"You": "You",
|
"You": "You",
|
||||||
"Logged_out_by_server": "You've been logged out by the server. Please log in again.",
|
"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_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",
|
"You_need_to_verifiy_your_email_address_to_get_notications": "You need to verify your email address to get notifications",
|
||||||
"Your_certificate": "Your Certificate",
|
"Your_certificate": "Your Certificate",
|
||||||
|
|
|
@ -65,8 +65,10 @@ const handleLoginRequest = function* handleLoginRequest({ credentials, logoutOnE
|
||||||
yield put(loginSuccess(result));
|
yield put(loginSuccess(result));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (logoutOnError && e.data && e.data.message && /you've been logged out by the server/i.test(e.data.message)) {
|
if (e?.data?.message && /you've been logged out by the server/i.test(e.data.message)) {
|
||||||
yield put(logout(true));
|
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 {
|
} else {
|
||||||
logEvent(events.LOGIN_DEFAULT_LOGIN_F);
|
logEvent(events.LOGIN_DEFAULT_LOGIN_F);
|
||||||
yield put(loginFailure(e));
|
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(encryptionStop());
|
||||||
yield put(appStart({ root: RootEnum.ROOT_LOADING, text: I18n.t('Logging_out') }));
|
yield put(appStart({ root: RootEnum.ROOT_LOADING, text: I18n.t('Logging_out') }));
|
||||||
const server = yield select(getServer);
|
const server = yield select(getServer);
|
||||||
|
@ -188,7 +190,9 @@ const handleLogout = function* handleLogout({ forcedByServer }) {
|
||||||
// if the user was logged out by the server
|
// if the user was logged out by the server
|
||||||
if (forcedByServer) {
|
if (forcedByServer) {
|
||||||
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
|
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);
|
yield delay(300);
|
||||||
EventEmitter.emit('NewServer', { server });
|
EventEmitter.emit('NewServer', { server });
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue