From 03c6fc8b5c6557e9a833b4491b3727070031e238 Mon Sep 17 00:00:00 2001 From: Satbir Singh Date: Wed, 8 Apr 2020 08:43:56 +0000 Subject: [PATCH] Fixed login error message. Wrong user email in segment after logout issue. --- app/client/src/sagas/ErrorSagas.tsx | 7 ++++++- app/client/src/sagas/userSagas.tsx | 25 ++++++++++++++----------- app/client/src/utils/AnalyticsUtil.tsx | 6 ++++++ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/client/src/sagas/ErrorSagas.tsx b/app/client/src/sagas/ErrorSagas.tsx index 4c19564071..bd117ed732 100644 --- a/app/client/src/sagas/ErrorSagas.tsx +++ b/app/client/src/sagas/ErrorSagas.tsx @@ -8,7 +8,7 @@ import { AppToaster } from "components/editorComponents/ToastComponent"; import { DEFAULT_ERROR_MESSAGE, DEFAULT_ACTION_ERROR } from "constants/errors"; import { ApiResponse } from "api/ApiResponses"; import { put, takeLatest, call } from "redux-saga/effects"; -import { ERROR_500, ERROR_0 } from "constants/messages"; +import { ERROR_401, ERROR_500, ERROR_0 } from "constants/messages"; import { ToastType } from "react-toastify"; export function* callAPI(apiCall: any, requestPayload: any) { @@ -20,6 +20,8 @@ export function* callAPI(apiCall: any, requestPayload: any) { } const getErrorMessage = (code: number) => { switch (code) { + case 401: + return ERROR_401; case 500: return ERROR_500; case 0: @@ -28,6 +30,9 @@ const getErrorMessage = (code: number) => { }; export function* validateResponse(response: ApiResponse | any) { + if (!response) { + throw Error(""); + } if (!response.responseMeta && !response.status) { throw Error(getErrorMessage(0)); } diff --git a/app/client/src/sagas/userSagas.tsx b/app/client/src/sagas/userSagas.tsx index 263d3b067c..b39b44ea55 100644 --- a/app/client/src/sagas/userSagas.tsx +++ b/app/client/src/sagas/userSagas.tsx @@ -1,4 +1,4 @@ -import { call, takeLatest, put, all } from "redux-saga/effects"; +import { call, takeLatest, put, all, delay } from "redux-saga/effects"; import { ReduxAction, ReduxActionWithPromise, @@ -275,6 +275,10 @@ export function* fetchUserSaga(action: ReduxAction) { applications, currentOrganization, }; + AnalyticsUtil.identifyUser(finalData.id, finalData); + Sentry.configureScope(function(scope) { + scope.setUser({ email: finalData.email, id: finalData.id }); + }); yield put({ type: ReduxActionTypes.FETCH_USER_SUCCESS, payload: finalData, @@ -284,22 +288,20 @@ export function* fetchUserSaga(action: ReduxAction) { return yield false; } catch (error) { console.log(error); - yield put({ - type: ReduxActionErrorTypes.FETCH_USER_ERROR, - payload: { - error, - }, - }); + if (error) { + yield put({ + type: ReduxActionErrorTypes.FETCH_USER_ERROR, + payload: { + error, + }, + }); + } } } export function* setCurrentUserSaga(action: ReduxAction) { const me = yield call(fetchUserSaga, action); if (me) { - AnalyticsUtil.identifyUser(me.id, me); - Sentry.configureScope(function(scope) { - scope.setUser({ email: me.email, id: me.id }); - }); resetAuthExpiration(); yield put({ type: ReduxActionTypes.SET_CURRENT_USER_SUCCESS, @@ -362,6 +364,7 @@ export function* logoutSaga() { const response: ApiResponse = yield call(UserApi.logoutUser); const isValidResponse = yield validateResponse(response); if (isValidResponse) { + AnalyticsUtil.reset(); yield put(logoutUserSuccess()); yield put(fetchCurrentUser()); } diff --git a/app/client/src/utils/AnalyticsUtil.tsx b/app/client/src/utils/AnalyticsUtil.tsx index 10cc441eb4..d13705e2a8 100644 --- a/app/client/src/utils/AnalyticsUtil.tsx +++ b/app/client/src/utils/AnalyticsUtil.tsx @@ -179,6 +179,12 @@ class AnalyticsUtil { windowDoc.analytics.identify(userId, userData); } } + + static reset() { + const windowDoc: any = window; + windowDoc.analytics.reset(); + windowDoc.mixpanel.reset(); + } } export default AnalyticsUtil;