diff --git a/src/entities/user/model/hooks/useOnLogin.ts b/src/entities/user/model/hooks/useOnLogin.ts index 2c115c958..52910e36d 100644 --- a/src/entities/user/model/hooks/useOnLogin.ts +++ b/src/entities/user/model/hooks/useOnLogin.ts @@ -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); diff --git a/src/features/Logout/lib/useLogout.ts b/src/features/Logout/lib/useLogout.ts index 8bd101f05..31f918e40 100644 --- a/src/features/Logout/lib/useLogout.ts +++ b/src/features/Logout/lib/useLogout.ts @@ -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'; @@ -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(); @@ -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, diff --git a/src/pages/AuthorizedRoutes.tsx b/src/pages/AuthorizedRoutes.tsx index a89b01516..5eeb0ee17 100644 --- a/src/pages/AuthorizedRoutes.tsx +++ b/src/pages/AuthorizedRoutes.tsx @@ -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'; @@ -48,10 +49,10 @@ function AuthorizedRoutes({ refreshToken }: Props) { } /> } /> } /> - - } /> + } /> + } /> ); diff --git a/src/shared/utils/hooks/useSessionBanners/useSessionBanners.ts b/src/shared/utils/hooks/useSessionBanners/useSessionBanners.ts index 91cd43b2f..dd5d94fda 100644 --- a/src/shared/utils/hooks/useSessionBanners/useSessionBanners.ts +++ b/src/shared/utils/hooks/useSessionBanners/useSessionBanners.ts @@ -1,4 +1,4 @@ -import { useEffect, useRef } from 'react'; +import { useRef } from 'react'; import { useBanners } from '~/entities/banner/model'; import { userModel } from '~/entities/user'; @@ -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; };