@@ -8,7 +8,8 @@ import { useRouter } from 'next/router' import { signOut } from 'next-auth/react' import styles from '#/app/layout/styles/styles.module.css' -import { useAppSelector } from '#/app/store/store' +import { useAppDispatch, useAppSelector } from '#/app/store/store' +import { resetUser } from '#/entities/user-account' import { TooltipCustom } from '#/shared' import { declineToken } from '#/shared/lib/helpers/get-token' import { IProps } from '#/shared/lib/types/entities' @@ -38,8 +39,14 @@ const convertLang = (toShort: T, lang: LangParam): LangRet } const InfoBar: React.FC = ({ device }) => { + const dispatch = useAppDispatch() const balance = useAppSelector((state) => state.balance.balance) const { email, first_name, last_name, profile_picture_link, account_type, show_balance } = useAppSelector((state) => state.user) + + const handleLogout = () => { + dispatch(resetUser()) + signOut() + } const [anchorEl, setAnchorEl] = React.useState(null) const [anchorEl2, setAnchorEl2] = React.useState(null) @@ -105,7 +112,7 @@ const InfoBar: React.FC = ({ device }) => { Мы уже работаем над этой проблемой. Попробуйте перезайти в аккаунт - @@ -259,9 +266,7 @@ const InfoBar: React.FC = ({ device }) => { { - signOut() - }} + onClick={handleLogout} sx={{ marginTop: '15px', cursor: 'pointer' }} > {''} @@ -124,6 +124,9 @@ export const userSlice = createSlice({ addReferral: (state, action) => { state.referral = action.payload }, + resetUser: (state) => { + return { ...initialState } + }, }, extraReducers: (builder) => { builder.addCase(getAllInfo.fulfilled, (state, action) => { @@ -146,6 +149,7 @@ export const userSlice = createSlice({ referral_code, show_balance, } = action.payload + state.uid = uid state.is_subscribed_to_emails = is_subscribed_to_emails state.account_type = account_type state.email = email @@ -173,4 +177,4 @@ export const userSlice = createSlice({ }, }) -export const { addReferral } = userSlice.actions +export const { addReferral, resetUser } = userSlice.actions @@ -1,2 +1,2 @@ -export { getAllInfo, userSlice } from './model/user-type-slice' +export { getAllInfo, userSlice, resetUser } from './model/user-type-slice' export * from './model' \ No newline at end of file @@ -1,18 +1,27 @@ import React, { useEffect } from 'react' import styles from './slow-loading.module.scss' +import { useAppDispatch } from '#/app/store/store' import { Loader } from '#/shared' import { CommonButton } from '#/shared/ui/button' +import { resetUser } from '#/entities/user-account' import { signOut, useSession } from 'next-auth/react' interface SlowLoadingProps { } export const SlowLoading = ({ }: SlowLoadingProps) => { + const dispatch = useAppDispatch() + + const handleLogout = () => { + dispatch(resetUser()) + signOut() + } + return (

Долгая загрузка

Предлагаем перезайти - signOut()} variant='primary'> + Выйти
@@ -10,6 +10,7 @@ import { getSession,SessionProvider } from 'next-auth/react' import { appWithTranslation } from 'next-i18next' import { store } from '#/app/store/store' +import { resetUser } from '#/entities/user-account' import { Error } from '#/shared' import { pingFangFont } from '#/shared/lib/constants/font/font' import { useBlockTelegram } from '#/shared/lib/hooks/use-block-telegram' @@ -32,6 +33,8 @@ axios.interceptors.response.use(async (response) => { const session = await getSession() if (!session) { + // Сбрасываем состояние пользователя перед редиректом + store.dispatch(resetUser()) window.location.href = '/login' } @@ -3,7 +3,8 @@ import { Box, Divider, Link, Menu, MenuItem, Typography } from '@mui/material' import Router from 'next/router' import { signOut, useSession } from 'next-auth/react' -import { useAppSelector } from '#/app/store/store' +import { useAppDispatch, useAppSelector } from '#/app/store/store' +import { resetUser } from '#/entities/user-account' interface IAccountMenu { anchorEl: HTMLElement | null @@ -13,10 +14,17 @@ interface IAccountMenu { export const AccountMenu: React.FC = ({ anchorEl, changeVisible, device = 'desktop' }) => { const { data } = useSession() + const dispatch = useAppDispatch() + const goAccount = async () => { await Router.push('/account') } + const handleLogout = () => { + dispatch(resetUser()) + signOut() + } + const open = Boolean(anchorEl) const desktop = device === 'desktop' @@ -119,7 +127,7 @@ export const AccountMenu: React.FC = ({ anchorEl, changeVisible, d signOut()} + onClick={handleLogout} sx={{ color: '#FF4170', lineHeight: '19.6px', @@ -181,7 +189,7 @@ export const AccountMenu: React.FC = ({ anchorEl, changeVisible, d signOut()} + onClick={handleLogout} sx={{ color: '#FF4170', lineHeight: '19.6px', @@ -24,6 +24,7 @@ import BusinessHost from '#/widgets/business-host/business-host' import { Info } from '#/widgets/business-info' import { Subscription } from '#/widgets/payment/model/payment' import { Referral } from '#/widgets/referral' +import { resetUser } from '#/entities/user-account/model/user-type-slice' import { scopes } from '../config' @@ -246,7 +247,10 @@ const Account: NextPageWithLayout = () => { }, }) - if (status === 200) await signOut() + if (status === 200) { + dispatch(resetUser()) + await signOut() + } } catch (err) {} } @@ -9,7 +9,7 @@ import InfoBar from '#/app/layout/ui/info-bar' import { useAppDispatch, useAppSelector } from '#/app/store/store' import { getUserBalance } from '#/entities/balance' import { useTheme } from '#/entities/theme' -import { getAllInfo } from '#/entities/user-account' +import { getAllInfo, resetUser } from '#/entities/user-account' import { ChangePasswordPlate } from '#/features/change-password-corp' import { ErrorReportPlate } from '#/features/error-report' import { BusinessErrorReportPlate } from '#/features/error-report/ui/business-error-report' @@ -40,6 +40,7 @@ export const Layout: React.FC = ({ children, titlePage, isLoader, h const { push } = useRouter() function logout() { + dispatch(resetUser()) signOut() push('/login') } @@ -52,10 +53,11 @@ export const Layout: React.FC = ({ children, titlePage, isLoader, h useEffect(() => { if (meStatus === 'failed') { + dispatch(resetUser()) signOut() push('/login') } - }, [meStatus]) + }, [meStatus, dispatch, push]) useEffect(() => { if (!data) return @@ -63,10 +65,20 @@ export const Layout: React.FC = ({ children, titlePage, isLoader, h if (!data.user || !data.access || !data.refresh) logout() }, [data]) + const lastAccessTokenRef = useRef(null) + const hasLoadedUserDataRef = useRef(false) + useEffect(() => { - if (!data) return - getUserData(data.access) - }, [data]) + if (!data?.access) return + + if (lastAccessTokenRef.current !== data.access || (!hasLoadedUserDataRef.current && meStatus === 'idle')) { + lastAccessTokenRef.current = data.access + hasLoadedUserDataRef.current = false + getUserData(data.access).then(() => { + hasLoadedUserDataRef.current = true + }) + } + }, [data?.access, meStatus]) const [requestDelay, setRequestDelay] = useState(false) @@ -9,15 +9,22 @@ import Link from 'next/link' import Router, { useRouter } from 'next/router' import { signOut, useSession } from 'next-auth/react' -import { useAppSelector } from '#/app/store/store' +import { useAppDispatch, useAppSelector } from '#/app/store/store' import { getAll, ResponseAllInfo } from '#/entities/user-account/model/user-type-slice' +import { resetUser } from '#/entities/user-account' import { menuListMiddle, menuListTop } from '../../side-menu/ui/side-menu' export const MainMenuMobile = memo(() => { + const dispatch = useAppDispatch() const { data, status } = useSession() const { pathname, push, asPath } = useRouter() + + const handleLogout = () => { + dispatch(resetUser()) + signOut() + } const goToMain = async () => { await Router.push('/') @@ -127,7 +134,7 @@ export const MainMenuMobile = memo(() => { />
- signOut()}> + @@ -52,7 +52,7 @@ export const Subscription: React.FC = ({ device }) => { export const Payment: React.FC = ({ device, changeClose }) => { const desktop = device === 'desktop' - const [offers, setOffers] = useState(null) + const [offers, setOffers] = useState([]) const [selectedOffer, setSelectedOffer] = useState(offers?.length ? offers[0].uid : '') @@ -91,7 +91,7 @@ export const Payment: React.FC = ({ device, changeClose }) paddingTop: desktop ? '15px' : 0, }} > - {offers?.map((offer) => { + {offers?.length && offers?.map((offer) => { return (