diff --git a/src/features/AuthStore/hooks/useAuth.tsx b/src/features/AuthStore/hooks/useAuth.tsx index 5e060e34..1eaf0a6b 100644 --- a/src/features/AuthStore/hooks/useAuth.tsx +++ b/src/features/AuthStore/hooks/useAuth.tsx @@ -89,8 +89,9 @@ export const useAuth = () => { if (!readToken()) { const token = await getTemporaryToken() token && await fetchUserInfo() + return Promise.resolve() } - return Promise.resolve() + return Promise.reject() } storeUser(loadedUser) @@ -204,20 +205,24 @@ export const useAuth = () => { }, [reChekNewDevice, userManager]) useEffect(() => { - if (!needCheckNewDeviсe) return undefined + if (!needCheckNewDeviсe && !user) return undefined const startCheckDevice = setInterval(checkNewDevice, 20000) isNewDeviceLogin && clearInterval(startCheckDevice) return () => clearInterval(startCheckDevice) - }, [checkNewDevice, + + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [ + checkNewDevice, isNewDeviceLogin, setIsNewDeviceLogin, ]) useEffect(() => { - // попытаемся обновить токен используя refresh_token const tryRenewToken = () => { - userManager.signinSilent().catch(logout) + userManager.signinSilent() + .catch(() => user && logout()) } + // попытаемся обновить токен используя refresh_token // если запросы вернули 401 | 403 window.addEventListener('FORBIDDEN_REQUEST', tryRenewToken) @@ -227,6 +232,7 @@ export const useAuth = () => { window.removeEventListener('FORBIDDEN_REQUEST', tryRenewToken) userManager.events.removeAccessTokenExpired(tryRenewToken) } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [userManager, logout]) useEffect(() => { diff --git a/src/features/HomePage/hooks.tsx b/src/features/HomePage/hooks.tsx index 104cdf16..efe3923c 100644 --- a/src/features/HomePage/hooks.tsx +++ b/src/features/HomePage/hooks.tsx @@ -56,7 +56,7 @@ export const useHomePage = () => { })() } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [userInfo]) + }, [userInfo?.email]) useEffect(() => { const dateLastOpenSmartBanner = localStorage.getItem('dateLastOpenSmartBanner') @@ -75,7 +75,7 @@ export const useHomePage = () => { timezoneOffset: getTimezoneOffset(selectedDate), }), // eslint-disable-next-line react-hooks/exhaustive-deps - [selectedDate], + [selectedDate, userInfo?.email], ) useEffect(() => { diff --git a/src/features/HomePage/index.tsx b/src/features/HomePage/index.tsx index e4e476a2..f5d94791 100644 --- a/src/features/HomePage/index.tsx +++ b/src/features/HomePage/index.tsx @@ -47,6 +47,7 @@ const Home = () => { {isMobileDevice ? null : } + {/* {userInfo?.email && } */} { +export const Matches = memo((props: Props) => { const { fetchMoreMatches, isFetching, @@ -72,4 +76,4 @@ export const Matches = (props: Props) => { {isMobileDevice ? mobileView : desktopView} ) -} +}) diff --git a/src/features/SportsFilter/components/SelectSport/styled.tsx b/src/features/SportsFilter/components/SelectSport/styled.tsx index 13e51081..6747afcc 100644 --- a/src/features/SportsFilter/components/SelectSport/styled.tsx +++ b/src/features/SportsFilter/components/SelectSport/styled.tsx @@ -56,7 +56,7 @@ export const Arrows = styled.span` ${({ active }) => ( active ? css` - transform: translate(-50%, -50%) rotate(135deg); + transform: translate(-50%) rotate(135deg); ` : css` transform: translate(-50%, -50%) rotate(315deg); diff --git a/src/features/StreamPlayer/index.tsx b/src/features/StreamPlayer/index.tsx index 46a4a3e1..0d550ab1 100644 --- a/src/features/StreamPlayer/index.tsx +++ b/src/features/StreamPlayer/index.tsx @@ -28,10 +28,8 @@ import { Controls } from './components/Controls' import RewindMobile from './components/RewindMobile' const tournamentsWithWatermark = { - 131: 'Spain', 316: 'Tunisia', 1136: 'Brasil', - 2032: 'Spain', } /** * HLS плеер, применяется на лайв и завершенных матчах @@ -114,7 +112,9 @@ export const StreamPlayer = (props: Props) => { {user - && Object.keys(tournamentsWithWatermark)?.includes(String(profile?.tournament.id)) + && Boolean( + tournamentsWithWatermark[profile?.tournament.id as keyof typeof tournamentsWithWatermark], + ) && playing && isLive && ( diff --git a/src/features/UserFavorites/hooks/index.tsx b/src/features/UserFavorites/hooks/index.tsx index 624c67e9..bffa44d4 100644 --- a/src/features/UserFavorites/hooks/index.tsx +++ b/src/features/UserFavorites/hooks/index.tsx @@ -21,6 +21,8 @@ import { useToggle } from 'hooks/useToggle' import { ProfileTypes, SportTypes } from 'config' +import { useAuthStore } from '../../AuthStore' + type ProfileType = { profile: ObjectWithName & { additionalInfo: ObjectWithName & { @@ -40,6 +42,7 @@ export type SuperTournament = ObjectWithName & { type Args = Parameters[0] export const useUserFavorites = () => { + const { userInfo } = useAuthStore() const [userFavorites, setUserFavorites] = useState([]) const [playerHighlight, setPlayerHighlight] = useState({} as ProfileType) @@ -78,7 +81,8 @@ export const useUserFavorites = () => { setUserFavorites(value) } }) - }, []) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [userInfo?.email]) const removeSuperTournament = (id: number) => { forEach(userFavorites, (item) => { diff --git a/src/features/UserFavorites/index.tsx b/src/features/UserFavorites/index.tsx index 4d7d4259..3f343a85 100644 --- a/src/features/UserFavorites/index.tsx +++ b/src/features/UserFavorites/index.tsx @@ -10,9 +10,9 @@ import map from 'lodash/map' import { FavoritesActions } from 'requests' import { Modal } from 'features/Modal' - import { ProfileLink } from 'features/ProfileLink' -import { Close } from '../../libs/objects/Close' + +import { Close } from 'libs/objects/Close' import { TooltipBlock } from './TooltipBlock' import { FavoritesToolip } from './FavoritesTooltip' @@ -29,6 +29,8 @@ import { ScrollWrapper, } from './styled' +import { useAuthStore } from '../AuthStore' + type Props = { marginTop?: number, } @@ -44,9 +46,14 @@ export const UserFavorites = ({ marginTop }: Props) => { userFavorites, } = useUserFavoritesStore() + const { user } = useAuthStore() const [position, setPosition] = useState(0) - useEffect(fetchFavorites, [fetchFavorites]) + useEffect(() => { + if (!user) return + fetchFavorites() + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [fetchFavorites]) const getPosition = (event: MouseEvent | FocusEvent) => { if (event.currentTarget) { diff --git a/src/helpers/callApi/logoutIfUnauthorized.tsx b/src/helpers/callApi/logoutIfUnauthorized.tsx index f7f68cdf..feffe52b 100644 --- a/src/helpers/callApi/logoutIfUnauthorized.tsx +++ b/src/helpers/callApi/logoutIfUnauthorized.tsx @@ -1,11 +1,9 @@ -import { removeToken } from '../token' - export const logoutIfUnauthorized = async (response: Response) => { /* отключили из-за доступа без авторизации */ - if (response.status === 401 || response.status === 403) { - removeToken() - window.dispatchEvent(new Event('FORBIDDEN_REQUEST')) - } + // if (response.status === 401 || response.status === 403) { + // removeToken() + // window.dispatchEvent(new Event('FORBIDDEN_REQUEST')) + // } const error = new Error(response.statusText) // eslint-disable-next-line no-console diff --git a/src/requests/getSound.tsx b/src/requests/getSound.tsx index 22634dcd..318ff00b 100644 --- a/src/requests/getSound.tsx +++ b/src/requests/getSound.tsx @@ -12,6 +12,6 @@ export const getSound = async (id: number | string): Promise => { return callApi({ config, - url: `${API_ROOT}/v1/highlights/music/${id}`, + url: `${API_ROOT}/v1/aws/highlights/music/${id}`, }) }