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.

feat: make identity call if user is logs in for first time or if identity call was not registered (#3612)

Yunus Md2d3c4bb3620
diff --git a/frontend/src/AppRoutes/index.tsx b/frontend/src/AppRoutes/index.tsx
index 4c46928163..38874ccd2a 100644
--- a/frontend/src/AppRoutes/index.tsx
+++ b/frontend/src/AppRoutes/index.tsx
@@ -1,7 +1,10 @@
import { ConfigProvider } from 'antd';
+import getLocalStorageApi from 'api/browser/localstorage/get';
+import setLocalStorageApi from 'api/browser/localstorage/set';
import NotFound from 'components/NotFound';
import Spinner from 'components/Spinner';
import { FeatureKeys } from 'constants/features';
+import { LOCALSTORAGE } from 'constants/localStorage';
import ROUTES from 'constants/routes';
import AppLayout from 'container/AppLayout';
import { useThemeConfig } from 'hooks/useDarkMode';
@@ -75,14 +78,24 @@ function App(): JSX.Element {
});
useEffect(() => {
- if (isLoggedInState && user && user.userId && user.email) {
+ const isIdentifiedUser = getLocalStorageApi(LOCALSTORAGE.IS_IDENTIFIED_USER);
+
+ if (
+ isLoggedInState &&
+ user &&
+ user.userId &&
+ user.email &&
+ !isIdentifiedUser
+ ) {
+ setLocalStorageApi(LOCALSTORAGE.IS_IDENTIFIED_USER, 'true');
+
window.analytics.identify(user?.email, {
email: user?.email,
name: user?.name,
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [isLoggedInState]);
+ }, [isLoggedInState, user]);
useEffect(() => {
trackPageView(pathname);
diff --git a/frontend/src/api/utils.ts b/frontend/src/api/utils.ts
index 2d31836733..140e793e35 100644
--- a/frontend/src/api/utils.ts
+++ b/frontend/src/api/utils.ts
@@ -14,7 +14,11 @@ import {
export const Logout = (): void => {
deleteLocalStorageKey(LOCALSTORAGE.AUTH_TOKEN);
deleteLocalStorageKey(LOCALSTORAGE.IS_LOGGED_IN);
+ deleteLocalStorageKey(LOCALSTORAGE.IS_IDENTIFIED_USER);
deleteLocalStorageKey(LOCALSTORAGE.REFRESH_AUTH_TOKEN);
+ deleteLocalStorageKey(LOCALSTORAGE.LOGGED_IN_USER_EMAIL);
+ deleteLocalStorageKey(LOCALSTORAGE.LOGGED_IN_USER_NAME);
+ deleteLocalStorageKey(LOCALSTORAGE.CHAT_SUPPORT);
store.dispatch({
type: LOGGED_IN,
diff --git a/frontend/src/constants/localStorage.ts b/frontend/src/constants/localStorage.ts
index b17ae3d34c..2788e93943 100644
--- a/frontend/src/constants/localStorage.ts
+++ b/frontend/src/constants/localStorage.ts
@@ -14,4 +14,5 @@ export enum LOCALSTORAGE {
LOGGED_IN_USER_NAME = 'LOGGED_IN_USER_NAME',
LOGGED_IN_USER_EMAIL = 'LOGGED_IN_USER_EMAIL',
CHAT_SUPPORT = 'CHAT_SUPPORT',
+ IS_IDENTIFIED_USER = 'IS_IDENTIFIED_USER',
}
diff --git a/frontend/src/container/Login/index.tsx b/frontend/src/container/Login/index.tsx
index 356d971aa9..df9a1c6a37 100644
--- a/frontend/src/container/Login/index.tsx
+++ b/frontend/src/container/Login/index.tsx
@@ -1,13 +1,9 @@
import { Button, Form, Input, Space, Tooltip, Typography } from 'antd';
-import setLocalStorageApi from 'api/browser/localstorage/set';
import getUserVersion from 'api/user/getVersion';
import loginApi from 'api/user/login';
import loginPrecheckApi from 'api/user/loginPrecheck';
import afterLogin from 'AppRoutes/utils';
-import { FeatureKeys } from 'constants/features';
-import { LOCALSTORAGE } from 'constants/localStorage';
import ROUTES from 'constants/routes';
-import useFeatureFlag from 'hooks/useFeatureFlag';
import { useNotifications } from 'hooks/useNotifications';
import history from 'lib/history';
import { useEffect, useState } from 'react';
@@ -42,9 +38,6 @@ function Login({
const { t } = useTranslation(['login']);
const [isLoading, setIsLoading] = useState<boolean>(false);
const { user } = useSelector<AppState, AppReducer>((state) => state.app);
- const isChatSupportEnabled: boolean | undefined = useFeatureFlag(
- FeatureKeys.CHAT_SUPPORT,
- )?.active;
const [precheckResult, setPrecheckResult] = useState<PrecheckResultType>({
sso: false,
@@ -165,21 +158,12 @@ function Login({
password,
});
if (response.statusCode === 200) {
- const user = await afterLogin(
+ await afterLogin(
response.payload.userId,
response.payload.accessJwt,
response.payload.refreshJwt,
);
- if (user) {
- setLocalStorageApi(LOCALSTORAGE.LOGGED_IN_USER_NAME, user.payload?.name);
- setLocalStorageApi(LOCALSTORAGE.LOGGED_IN_USER_EMAIL, user.payload?.email);
- setLocalStorageApi(
- LOCALSTORAGE.CHAT_SUPPORT,
- (isChatSupportEnabled || '').toString(),
- );
- }
-
history.push(ROUTES.APPLICATION);
} else {
notifications.error({