mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 01:15:52 +08:00
chore: logout is updated (#1100)
This commit is contained in:
parent
b9f3663b6c
commit
084d8ecccd
@ -1,11 +1,8 @@
|
||||
import { notification } from 'antd';
|
||||
import getLocalStorageApi from 'api/browser/localstorage/get';
|
||||
import setLocalStorageApi from 'api/browser/localstorage/set';
|
||||
import getUserApi from 'api/user/getUser';
|
||||
import { Logout } from 'api/utils';
|
||||
import { LOCALSTORAGE } from 'constants/localStorage';
|
||||
import ROUTES from 'constants/routes';
|
||||
import { t } from 'i18next';
|
||||
import history from 'lib/history';
|
||||
import store from 'store';
|
||||
import AppActions from 'types/actions';
|
||||
import {
|
||||
@ -86,11 +83,8 @@ const afterLogin = async (
|
||||
},
|
||||
});
|
||||
|
||||
notification.error({
|
||||
message: getUserResponse.error || t('something_went_wrong'),
|
||||
});
|
||||
Logout();
|
||||
|
||||
history.push(ROUTES.SOMETHING_WENT_WRONG);
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
@ -3,19 +3,17 @@ import { LOCALSTORAGE } from 'constants/localStorage';
|
||||
import ROUTES from 'constants/routes';
|
||||
import history from 'lib/history';
|
||||
import store from 'store';
|
||||
import { LOGGED_IN, UPDATE_USER_IS_FETCH } from 'types/actions/app';
|
||||
import {
|
||||
LOGGED_IN,
|
||||
UPDATE_USER,
|
||||
UPDATE_USER_ACCESS_REFRESH_ACCESS_TOKEN,
|
||||
UPDATE_USER_ORG_ROLE,
|
||||
} from 'types/actions/app';
|
||||
|
||||
export const Logout = (): void => {
|
||||
deleteLocalStorageKey(LOCALSTORAGE.REFRESH_AUTH_TOKEN);
|
||||
deleteLocalStorageKey(LOCALSTORAGE.AUTH_TOKEN);
|
||||
deleteLocalStorageKey(LOCALSTORAGE.IS_LOGGED_IN);
|
||||
|
||||
store.dispatch({
|
||||
type: UPDATE_USER_IS_FETCH,
|
||||
payload: {
|
||||
isUserFetching: false,
|
||||
},
|
||||
});
|
||||
deleteLocalStorageKey(LOCALSTORAGE.REFRESH_AUTH_TOKEN);
|
||||
|
||||
store.dispatch({
|
||||
type: LOGGED_IN,
|
||||
@ -24,6 +22,34 @@ export const Logout = (): void => {
|
||||
},
|
||||
});
|
||||
|
||||
// navigate to login
|
||||
store.dispatch({
|
||||
type: UPDATE_USER_ORG_ROLE,
|
||||
payload: {
|
||||
org: null,
|
||||
role: null,
|
||||
},
|
||||
});
|
||||
|
||||
store.dispatch({
|
||||
type: UPDATE_USER,
|
||||
payload: {
|
||||
ROLE: 'VIEWER',
|
||||
email: '',
|
||||
name: '',
|
||||
orgId: '',
|
||||
orgName: '',
|
||||
profilePictureURL: '',
|
||||
userId: '',
|
||||
},
|
||||
});
|
||||
|
||||
store.dispatch({
|
||||
type: UPDATE_USER_ACCESS_REFRESH_ACCESS_TOKEN,
|
||||
payload: {
|
||||
accessJwt: '',
|
||||
refreshJwt: '',
|
||||
},
|
||||
});
|
||||
|
||||
history.push(ROUTES.LOGIN);
|
||||
};
|
||||
|
@ -12,25 +12,17 @@ import {
|
||||
Space,
|
||||
Typography,
|
||||
} from 'antd';
|
||||
import remove from 'api/browser/localstorage/remove';
|
||||
import { LOCALSTORAGE } from 'constants/localStorage';
|
||||
import { Logout } from 'api/utils';
|
||||
import ROUTES from 'constants/routes';
|
||||
import history from 'lib/history';
|
||||
import setTheme, { AppMode } from 'lib/theme/setTheme';
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import { connect, useDispatch, useSelector } from 'react-redux';
|
||||
import { connect, useSelector } from 'react-redux';
|
||||
import { NavLink } from 'react-router-dom';
|
||||
import { bindActionCreators, Dispatch } from 'redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { ThunkDispatch } from 'redux-thunk';
|
||||
import { ToggleDarkMode } from 'store/actions';
|
||||
import { AppState } from 'store/reducers';
|
||||
import AppActions from 'types/actions';
|
||||
import {
|
||||
LOGGED_IN,
|
||||
UPDATE_USER,
|
||||
UPDATE_USER_ACCESS_REFRESH_ACCESS_TOKEN,
|
||||
UPDATE_USER_ORG_ROLE,
|
||||
} from 'types/actions/app';
|
||||
import AppReducer from 'types/reducer/app';
|
||||
|
||||
import CurrentOrganization from './CurrentOrganization';
|
||||
@ -47,7 +39,6 @@ function HeaderContainer({ toggleDarkMode }: Props): JSX.Element {
|
||||
(state) => state.app,
|
||||
);
|
||||
const [isUserDropDownOpen, setIsUserDropDownOpen] = useState<boolean>();
|
||||
const dispatch = useDispatch<Dispatch<AppActions>>();
|
||||
|
||||
const onToggleThemeHandler = useCallback(() => {
|
||||
const preMode: AppMode = isDarkMode ? 'lightMode' : 'darkMode';
|
||||
@ -75,43 +66,7 @@ function HeaderContainer({ toggleDarkMode }: Props): JSX.Element {
|
||||
};
|
||||
|
||||
const onClickLogoutHandler = (): void => {
|
||||
remove(LOCALSTORAGE.AUTH_TOKEN);
|
||||
remove(LOCALSTORAGE.IS_LOGGED_IN);
|
||||
remove(LOCALSTORAGE.REFRESH_AUTH_TOKEN);
|
||||
dispatch({
|
||||
type: LOGGED_IN,
|
||||
payload: {
|
||||
isLoggedIn: false,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: UPDATE_USER_ORG_ROLE,
|
||||
payload: {
|
||||
org: null,
|
||||
role: null,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: UPDATE_USER,
|
||||
payload: {
|
||||
ROLE: 'VIEWER',
|
||||
email: '',
|
||||
name: '',
|
||||
orgId: '',
|
||||
orgName: '',
|
||||
profilePictureURL: '',
|
||||
userId: '',
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: UPDATE_USER_ACCESS_REFRESH_ACCESS_TOKEN,
|
||||
payload: {
|
||||
accessJwt: '',
|
||||
refreshJwt: '',
|
||||
},
|
||||
});
|
||||
|
||||
history.push(ROUTES.LOGIN);
|
||||
Logout();
|
||||
};
|
||||
|
||||
const menu = (
|
||||
|
Loading…
x
Reference in New Issue
Block a user