Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions frontend/src/AppRoutes/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/constants/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
18 changes: 1 addition & 17 deletions frontend/src/container/Login/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down
Loading