Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

chore: logout is updated (#1100)

palash-signoz084d8ecccdea
diff --git a/frontend/src/AppRoutes/utils.ts b/frontend/src/AppRoutes/utils.ts
index 5f3405ceea..698629d325 100644
--- a/frontend/src/AppRoutes/utils.ts
+++ b/frontend/src/AppRoutes/utils.ts
@@ -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;
};
diff --git a/frontend/src/api/utils.ts b/frontend/src/api/utils.ts
index 3e3d720477..56867927a8 100644
--- a/frontend/src/api/utils.ts
+++ b/frontend/src/api/utils.ts
@@ -3,27 +3,53 @@ 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);
+ deleteLocalStorageKey(LOCALSTORAGE.REFRESH_AUTH_TOKEN);
store.dispatch({
- type: UPDATE_USER_IS_FETCH,
+ type: LOGGED_IN,
payload: {
- isUserFetching: false,
+ isLoggedIn: false,
},
});
store.dispatch({
- type: LOGGED_IN,
+ type: UPDATE_USER_ORG_ROLE,
payload: {
- isLoggedIn: false,
+ 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: '',
},
});
- // navigate to login
history.push(ROUTES.LOGIN);
};
diff --git a/frontend/src/container/Header/index.tsx b/frontend/src/container/Header/index.tsx
index d3f1436f9a..c3c9eb8e84 100644
--- a/frontend/src/container/Header/index.tsx
+++ b/frontend/src/container/Header/index.tsx
@@ -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 = (