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

fix: Warning banner & post-login redirect both fail when starting Take Now while already logged into Web App as wrong respondent (M2-8029) #539

Merged
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
2 changes: 1 addition & 1 deletion src/entities/user/model/hooks/useOnLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const useOnLogin = (params: Params) => {
secureTokensStorage.setTokens(tokens);

if (params.backRedirectPath !== undefined) {
navigate(params.backRedirectPath);
navigate(params.backRedirectPath, { replace: true });
} else {
Mixpanel.track('Login Successful');
Mixpanel.login(user.id);
Expand Down
17 changes: 15 additions & 2 deletions src/features/Logout/lib/useLogout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useCallback } from 'react';

import { useLocation } from 'react-router-dom';

import { appletModel } from '~/entities/applet';
import { useLogoutMutation, userModel } from '~/entities/user';
import { AutoCompletionModel } from '~/features/AutoCompletion';
Expand All @@ -14,6 +16,7 @@ type UseLogoutReturn = {

export const useLogout = (): UseLogoutReturn => {
const navigator = useCustomNavigation();
const location = useLocation();

const { clearUser } = userModel.hooks.useUserState();
const { clearStore } = appletModel.hooks.useClearStore();
Expand All @@ -37,8 +40,18 @@ export const useLogout = (): UseLogoutReturn => {
Mixpanel.track('logout');
Mixpanel.logout();
FeatureFlags.logout();
return navigator.navigate(ROUTES.login.path);
}, [clearUser, clearStore, clearAutoCompletionState, navigator, logoutMutation]);

const backRedirectPath = `${location.pathname}${location.search}`;
return navigator.navigate(ROUTES.login.path, { state: { backRedirectPath } });
}, [
clearUser,
clearStore,
clearAutoCompletionState,
location.pathname,
location.search,
navigator,
logoutMutation,
]);

return {
logout,
Expand Down
5 changes: 3 additions & 2 deletions src/pages/AuthorizedRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Navigate, Route, Routes } from 'react-router-dom';
import AppletDetailsPage from './AppletDetailsPage';
import AppletListPage from './AppletListPage';
import AutoCompletion from './AutoCompletion';
import LoginPage from './Login';
import ProfilePage from './Profile';
import PublicAutoCompletion from './PublicAutoCompletion';
import SettingsPage from './Settings';
Expand Down Expand Up @@ -48,10 +49,10 @@ function AuthorizedRoutes({ refreshToken }: Props) {
<Route path={ROUTES.privateJoin.path} element={<PrivateJoinPage />} />
<Route path={ROUTES.publicJoin.path} element={<PublicAppletDetailsPage />} />
<Route path={ROUTES.transferOwnership.path} element={<TransferOwnershipPage />} />

<Route path="*" element={<Navigate to={ROUTES.appletList.path} />} />
</Route>
</Route>
<Route path={ROUTES.login.path} element={<LoginPage />} />
<Route path="*" element={<Navigate to={ROUTES.appletList.path} />} />
</Routes>
</LogoutTracker>
);
Expand Down
12 changes: 5 additions & 7 deletions src/shared/utils/hooks/useSessionBanners/useSessionBanners.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef } from 'react';
import { useRef } from 'react';

import { useBanners } from '~/entities/banner/model';
import { userModel } from '~/entities/user';
Expand All @@ -9,11 +9,9 @@ export const useSessionBanners = () => {

const prevIsAuthorized = useRef(isAuthorized);

useEffect(() => {
if (prevIsAuthorized.current !== isAuthorized && !isAuthorized) {
removeAllBanners();
}
if (prevIsAuthorized.current !== isAuthorized && !isAuthorized) {
removeAllBanners();
}

prevIsAuthorized.current = isAuthorized;
}, [isAuthorized, removeAllBanners]);
prevIsAuthorized.current = isAuthorized;
};
Loading