mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 17:15:55 +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 getLocalStorageApi from 'api/browser/localstorage/get';
|
||||||
import setLocalStorageApi from 'api/browser/localstorage/set';
|
import setLocalStorageApi from 'api/browser/localstorage/set';
|
||||||
import getUserApi from 'api/user/getUser';
|
import getUserApi from 'api/user/getUser';
|
||||||
|
import { Logout } from 'api/utils';
|
||||||
import { LOCALSTORAGE } from 'constants/localStorage';
|
import { LOCALSTORAGE } from 'constants/localStorage';
|
||||||
import ROUTES from 'constants/routes';
|
|
||||||
import { t } from 'i18next';
|
|
||||||
import history from 'lib/history';
|
|
||||||
import store from 'store';
|
import store from 'store';
|
||||||
import AppActions from 'types/actions';
|
import AppActions from 'types/actions';
|
||||||
import {
|
import {
|
||||||
@ -86,11 +83,8 @@ const afterLogin = async (
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
notification.error({
|
Logout();
|
||||||
message: getUserResponse.error || t('something_went_wrong'),
|
|
||||||
});
|
|
||||||
|
|
||||||
history.push(ROUTES.SOMETHING_WENT_WRONG);
|
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,19 +3,17 @@ import { LOCALSTORAGE } from 'constants/localStorage';
|
|||||||
import ROUTES from 'constants/routes';
|
import ROUTES from 'constants/routes';
|
||||||
import history from 'lib/history';
|
import history from 'lib/history';
|
||||||
import store from 'store';
|
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 => {
|
export const Logout = (): void => {
|
||||||
deleteLocalStorageKey(LOCALSTORAGE.REFRESH_AUTH_TOKEN);
|
|
||||||
deleteLocalStorageKey(LOCALSTORAGE.AUTH_TOKEN);
|
deleteLocalStorageKey(LOCALSTORAGE.AUTH_TOKEN);
|
||||||
deleteLocalStorageKey(LOCALSTORAGE.IS_LOGGED_IN);
|
deleteLocalStorageKey(LOCALSTORAGE.IS_LOGGED_IN);
|
||||||
|
deleteLocalStorageKey(LOCALSTORAGE.REFRESH_AUTH_TOKEN);
|
||||||
store.dispatch({
|
|
||||||
type: UPDATE_USER_IS_FETCH,
|
|
||||||
payload: {
|
|
||||||
isUserFetching: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
store.dispatch({
|
store.dispatch({
|
||||||
type: LOGGED_IN,
|
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);
|
history.push(ROUTES.LOGIN);
|
||||||
};
|
};
|
||||||
|
@ -12,25 +12,17 @@ import {
|
|||||||
Space,
|
Space,
|
||||||
Typography,
|
Typography,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import remove from 'api/browser/localstorage/remove';
|
import { Logout } from 'api/utils';
|
||||||
import { LOCALSTORAGE } from 'constants/localStorage';
|
|
||||||
import ROUTES from 'constants/routes';
|
import ROUTES from 'constants/routes';
|
||||||
import history from 'lib/history';
|
|
||||||
import setTheme, { AppMode } from 'lib/theme/setTheme';
|
import setTheme, { AppMode } from 'lib/theme/setTheme';
|
||||||
import React, { useCallback, useState } from 'react';
|
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 { NavLink } from 'react-router-dom';
|
||||||
import { bindActionCreators, Dispatch } from 'redux';
|
import { bindActionCreators } from 'redux';
|
||||||
import { ThunkDispatch } from 'redux-thunk';
|
import { ThunkDispatch } from 'redux-thunk';
|
||||||
import { ToggleDarkMode } from 'store/actions';
|
import { ToggleDarkMode } from 'store/actions';
|
||||||
import { AppState } from 'store/reducers';
|
import { AppState } from 'store/reducers';
|
||||||
import AppActions from 'types/actions';
|
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 AppReducer from 'types/reducer/app';
|
||||||
|
|
||||||
import CurrentOrganization from './CurrentOrganization';
|
import CurrentOrganization from './CurrentOrganization';
|
||||||
@ -47,7 +39,6 @@ function HeaderContainer({ toggleDarkMode }: Props): JSX.Element {
|
|||||||
(state) => state.app,
|
(state) => state.app,
|
||||||
);
|
);
|
||||||
const [isUserDropDownOpen, setIsUserDropDownOpen] = useState<boolean>();
|
const [isUserDropDownOpen, setIsUserDropDownOpen] = useState<boolean>();
|
||||||
const dispatch = useDispatch<Dispatch<AppActions>>();
|
|
||||||
|
|
||||||
const onToggleThemeHandler = useCallback(() => {
|
const onToggleThemeHandler = useCallback(() => {
|
||||||
const preMode: AppMode = isDarkMode ? 'lightMode' : 'darkMode';
|
const preMode: AppMode = isDarkMode ? 'lightMode' : 'darkMode';
|
||||||
@ -75,43 +66,7 @@ function HeaderContainer({ toggleDarkMode }: Props): JSX.Element {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onClickLogoutHandler = (): void => {
|
const onClickLogoutHandler = (): void => {
|
||||||
remove(LOCALSTORAGE.AUTH_TOKEN);
|
Logout();
|
||||||
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);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const menu = (
|
const menu = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user