diff --git a/src/features/AuthServiceApp/components/Login/hooks.tsx b/src/features/AuthServiceApp/components/Login/hooks.tsx index 04c3b4fb..1eb24230 100644 --- a/src/features/AuthServiceApp/components/Login/hooks.tsx +++ b/src/features/AuthServiceApp/components/Login/hooks.tsx @@ -19,6 +19,7 @@ import { useAuthFields } from 'features/AuthServiceApp/hooks/useAuthFields' import { AuthProviders } from '../../config/authProviders' import { getAuthUrl } from '../../helpers/getAuthUrl' import { useParamsUrl } from '../../hooks/useParamsUrl' +import { addAccessTokenToUrl } from '../../../../helpers/languageUrlParam' const url = getApiUrl('/authorize') @@ -38,7 +39,6 @@ export const useLoginForm = () => { const [isRecoveryPopupOpen, setIsRecoveryPopupOpen] = useState(false) const formRef = useRef(null) - const { email, error: formError, @@ -134,6 +134,6 @@ export const useLoginForm = () => { response_type, scope, setIsRecoveryPopupOpen, - url, + url: addAccessTokenToUrl(url), } } diff --git a/src/features/AuthServiceApp/components/Oauth/hooks.tsx b/src/features/AuthServiceApp/components/Oauth/hooks.tsx index c5bbfdd0..bf02cac9 100644 --- a/src/features/AuthServiceApp/components/Oauth/hooks.tsx +++ b/src/features/AuthServiceApp/components/Oauth/hooks.tsx @@ -10,6 +10,8 @@ import { import { isValidEmail } from 'features/AuthServiceApp/helpers/isValidEmail' +import { addAccessTokenToUrl } from 'helpers/languageUrlParam' + import { API_ROOT } from '../../config/routes' export const useOauth = () => { @@ -24,7 +26,7 @@ export const useOauth = () => { const authorize = useCallback(async () => { if (!formRef.current) return - const url = `${API_ROOT}/oauth` + const url = addAccessTokenToUrl(`${API_ROOT}/oauth`) const res = await fetch(url, { body: new FormData(formRef.current), diff --git a/src/features/AuthServiceApp/requests/auth.tsx b/src/features/AuthServiceApp/requests/auth.tsx index f6559430..612e48e3 100644 --- a/src/features/AuthServiceApp/requests/auth.tsx +++ b/src/features/AuthServiceApp/requests/auth.tsx @@ -1,7 +1,6 @@ import { getApiUrl } from '../config/routes' import type { UrlParams } from './register' -import { checkCookie } from '../../../helpers/cookie' const errorLexics = { 1: 'error_invalid_email_or_password', @@ -42,9 +41,7 @@ export const loginCheck = async ({ }), method: 'POST', } - const response = await fetch(`${url}${checkCookie('access_token') - ? `&${checkCookie('access_token')}` - : ''}`, init) + const response = await fetch(url, init) const body: SuccessResponse | FailedResponse = await response.json() diff --git a/src/features/MatchPage/index.tsx b/src/features/MatchPage/index.tsx index 112a6a4d..6851a6e5 100644 --- a/src/features/MatchPage/index.tsx +++ b/src/features/MatchPage/index.tsx @@ -31,7 +31,11 @@ const MatchPageComponent = () => { const history = useHistory() const { addRemoveFavorite, userFavorites } = useUserFavoritesStore() - const { isStarted, profile } = useMatchPageStore() + const { + isStarted, + profile, + user, + } = useMatchPageStore() const isFavorite = profile && userFavorites.find((fav) => fav.id === profile?.tournament.id) const { @@ -100,7 +104,7 @@ const MatchPageComponent = () => { { - (profile?.tournament.id === 131 || profile?.tournament.id === 2032) + user && (profile?.tournament.id === 131 || profile?.tournament.id === 2032) && } diff --git a/src/features/MatchPage/store/hooks/index.tsx b/src/features/MatchPage/store/hooks/index.tsx index 015465ea..9ca61451 100644 --- a/src/features/MatchPage/store/hooks/index.tsx +++ b/src/features/MatchPage/store/hooks/index.tsx @@ -238,6 +238,7 @@ export const useMatchPage = () => { toggleActivePlayers, togglePopup, tournamentData, + user, watchAllEpisodesTimer, } } diff --git a/src/features/TournamentPage/hooks.tsx b/src/features/TournamentPage/hooks.tsx index bf414af0..093c61e2 100644 --- a/src/features/TournamentPage/hooks.tsx +++ b/src/features/TournamentPage/hooks.tsx @@ -20,6 +20,7 @@ import { usePageParams } from 'hooks/usePageParams' import { useName } from 'features/Name' import { isPermittedTournament } from '../../helpers/isPermittedTournament' import { useProfileCard } from '../ProfileCard/hooks' +import { useAuthStore } from '../AuthStore' import { useBuyMatchPopupStore } from '../BuyMatchPopup' import { MATCH_CONFIG } from '../BuyMatchPopup/store/hooks/useSubscriptions' import { prepareMatchProfile } from '../MatchPage/helpers/prepareMatchProfile' @@ -30,6 +31,7 @@ export const useTournamentPage = () => { const { open: openBuyMatchPopup } = useBuyMatchPopupStore() const country = useName(tournamentProfile?.country || {}) const history = useHistory() + const { user } = useAuthStore() const { isFavorite, toggleFavorites } = useProfileCard() @@ -94,5 +96,6 @@ export const useTournamentPage = () => { infoItems: [country], profile, tournamentId, + user, } } diff --git a/src/features/TournamentPage/index.tsx b/src/features/TournamentPage/index.tsx index 9a0d9655..662c4793 100644 --- a/src/features/TournamentPage/index.tsx +++ b/src/features/TournamentPage/index.tsx @@ -21,6 +21,7 @@ const TournamentPage = () => { headerImage, profile, tournamentId, + user, } = useTournamentPage() return ( @@ -37,7 +38,7 @@ const TournamentPage = () => { - {(tournamentId === 131 || tournamentId === 2032) && } + {user && (tournamentId === 131 || tournamentId === 2032) && } ) } diff --git a/src/helpers/cookie/index.tsx b/src/helpers/cookie/index.tsx index af9f563c..cbad2d33 100644 --- a/src/helpers/cookie/index.tsx +++ b/src/helpers/cookie/index.tsx @@ -24,8 +24,8 @@ export const removeCookie = (name: string, domain = getDomain()) => { export const checkCookie = (name: string) => { const cookies = document.cookie - const token = cookies.split('; ') - .filter((cookie: string) => cookie.includes(name)) + const token = cookies?.split('; ') + ?.filter((cookie: string) => cookie?.includes(name)) return token[0] } diff --git a/src/helpers/languageUrlParam/index.tsx b/src/helpers/languageUrlParam/index.tsx index a3e7aa6f..98f04dd5 100644 --- a/src/helpers/languageUrlParam/index.tsx +++ b/src/helpers/languageUrlParam/index.tsx @@ -2,6 +2,7 @@ import isNull from 'lodash/isNull' import { history } from 'config/history' import { client } from 'config/clients' +import { checkCookie } from '../cookie' const KEY = 'lang' @@ -15,3 +16,10 @@ export const addLanguageUrlParam = (lang: string, url: string) => { urlObject.searchParams.set(KEY, lang) return urlObject.toString() } + +export const addAccessTokenToUrl = (url: string) => { + const urlObject = new URL(url) + const token = checkCookie('access_token')?.split('=') + token && urlObject.searchParams.set(token[0], token[1]) + return urlObject.toString() +}