fix(#175): add token in facebook and google auth

pull/39/head
Andrei Dekterev 3 years ago
parent 20d5c3eae4
commit 90af38ce77
  1. 4
      src/features/AuthServiceApp/components/Login/hooks.tsx
  2. 4
      src/features/AuthServiceApp/components/Oauth/hooks.tsx
  3. 5
      src/features/AuthServiceApp/requests/auth.tsx
  4. 8
      src/features/MatchPage/index.tsx
  5. 1
      src/features/MatchPage/store/hooks/index.tsx
  6. 3
      src/features/TournamentPage/hooks.tsx
  7. 3
      src/features/TournamentPage/index.tsx
  8. 4
      src/helpers/cookie/index.tsx
  9. 8
      src/helpers/languageUrlParam/index.tsx

@ -19,6 +19,7 @@ import { useAuthFields } from 'features/AuthServiceApp/hooks/useAuthFields'
import { AuthProviders } from '../../config/authProviders' import { AuthProviders } from '../../config/authProviders'
import { getAuthUrl } from '../../helpers/getAuthUrl' import { getAuthUrl } from '../../helpers/getAuthUrl'
import { useParamsUrl } from '../../hooks/useParamsUrl' import { useParamsUrl } from '../../hooks/useParamsUrl'
import { addAccessTokenToUrl } from '../../../../helpers/languageUrlParam'
const url = getApiUrl('/authorize') const url = getApiUrl('/authorize')
@ -38,7 +39,6 @@ export const useLoginForm = () => {
const [isRecoveryPopupOpen, setIsRecoveryPopupOpen] = useState(false) const [isRecoveryPopupOpen, setIsRecoveryPopupOpen] = useState(false)
const formRef = useRef<HTMLFormElement>(null) const formRef = useRef<HTMLFormElement>(null)
const { const {
email, email,
error: formError, error: formError,
@ -134,6 +134,6 @@ export const useLoginForm = () => {
response_type, response_type,
scope, scope,
setIsRecoveryPopupOpen, setIsRecoveryPopupOpen,
url, url: addAccessTokenToUrl(url),
} }
} }

@ -10,6 +10,8 @@ import {
import { isValidEmail } from 'features/AuthServiceApp/helpers/isValidEmail' import { isValidEmail } from 'features/AuthServiceApp/helpers/isValidEmail'
import { addAccessTokenToUrl } from 'helpers/languageUrlParam'
import { API_ROOT } from '../../config/routes' import { API_ROOT } from '../../config/routes'
export const useOauth = () => { export const useOauth = () => {
@ -24,7 +26,7 @@ export const useOauth = () => {
const authorize = useCallback(async () => { const authorize = useCallback(async () => {
if (!formRef.current) return if (!formRef.current) return
const url = `${API_ROOT}/oauth` const url = addAccessTokenToUrl(`${API_ROOT}/oauth`)
const res = await fetch(url, { const res = await fetch(url, {
body: new FormData(formRef.current), body: new FormData(formRef.current),

@ -1,7 +1,6 @@
import { getApiUrl } from '../config/routes' import { getApiUrl } from '../config/routes'
import type { UrlParams } from './register' import type { UrlParams } from './register'
import { checkCookie } from '../../../helpers/cookie'
const errorLexics = { const errorLexics = {
1: 'error_invalid_email_or_password', 1: 'error_invalid_email_or_password',
@ -42,9 +41,7 @@ export const loginCheck = async ({
}), }),
method: 'POST', method: 'POST',
} }
const response = await fetch(`${url}${checkCookie('access_token') const response = await fetch(url, init)
? `&${checkCookie('access_token')}`
: ''}`, init)
const body: SuccessResponse | FailedResponse = await response.json() const body: SuccessResponse | FailedResponse = await response.json()

@ -31,7 +31,11 @@ const MatchPageComponent = () => {
const history = useHistory() const history = useHistory()
const { addRemoveFavorite, userFavorites } = useUserFavoritesStore() 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 isFavorite = profile && userFavorites.find((fav) => fav.id === profile?.tournament.id)
const { const {
@ -100,7 +104,7 @@ const MatchPageComponent = () => {
</SubscriptionGuard> </SubscriptionGuard>
</Main> </Main>
{ {
(profile?.tournament.id === 131 || profile?.tournament.id === 2032) user && (profile?.tournament.id === 131 || profile?.tournament.id === 2032)
&& <FavouriteTeamPopup /> && <FavouriteTeamPopup />
} }
</PageWrapper> </PageWrapper>

@ -238,6 +238,7 @@ export const useMatchPage = () => {
toggleActivePlayers, toggleActivePlayers,
togglePopup, togglePopup,
tournamentData, tournamentData,
user,
watchAllEpisodesTimer, watchAllEpisodesTimer,
} }
} }

@ -20,6 +20,7 @@ import { usePageParams } from 'hooks/usePageParams'
import { useName } from 'features/Name' import { useName } from 'features/Name'
import { isPermittedTournament } from '../../helpers/isPermittedTournament' import { isPermittedTournament } from '../../helpers/isPermittedTournament'
import { useProfileCard } from '../ProfileCard/hooks' import { useProfileCard } from '../ProfileCard/hooks'
import { useAuthStore } from '../AuthStore'
import { useBuyMatchPopupStore } from '../BuyMatchPopup' import { useBuyMatchPopupStore } from '../BuyMatchPopup'
import { MATCH_CONFIG } from '../BuyMatchPopup/store/hooks/useSubscriptions' import { MATCH_CONFIG } from '../BuyMatchPopup/store/hooks/useSubscriptions'
import { prepareMatchProfile } from '../MatchPage/helpers/prepareMatchProfile' import { prepareMatchProfile } from '../MatchPage/helpers/prepareMatchProfile'
@ -30,6 +31,7 @@ export const useTournamentPage = () => {
const { open: openBuyMatchPopup } = useBuyMatchPopupStore() const { open: openBuyMatchPopup } = useBuyMatchPopupStore()
const country = useName(tournamentProfile?.country || {}) const country = useName(tournamentProfile?.country || {})
const history = useHistory() const history = useHistory()
const { user } = useAuthStore()
const { isFavorite, toggleFavorites } = useProfileCard() const { isFavorite, toggleFavorites } = useProfileCard()
@ -94,5 +96,6 @@ export const useTournamentPage = () => {
infoItems: [country], infoItems: [country],
profile, profile,
tournamentId, tournamentId,
user,
} }
} }

@ -21,6 +21,7 @@ const TournamentPage = () => {
headerImage, headerImage,
profile, profile,
tournamentId, tournamentId,
user,
} = useTournamentPage() } = useTournamentPage()
return ( return (
@ -37,7 +38,7 @@ const TournamentPage = () => {
<Matches fetch={fetchMatches} /> <Matches fetch={fetchMatches} />
</Content> </Content>
</Main> </Main>
{(tournamentId === 131 || tournamentId === 2032) && <FavouriteTeamPopup />} {user && (tournamentId === 131 || tournamentId === 2032) && <FavouriteTeamPopup />}
</PageWrapper> </PageWrapper>
) )
} }

@ -24,8 +24,8 @@ export const removeCookie = (name: string, domain = getDomain()) => {
export const checkCookie = (name: string) => { export const checkCookie = (name: string) => {
const cookies = document.cookie const cookies = document.cookie
const token = cookies.split('; ') const token = cookies?.split('; ')
.filter((cookie: string) => cookie.includes(name)) ?.filter((cookie: string) => cookie?.includes(name))
return token[0] return token[0]
} }

@ -2,6 +2,7 @@ import isNull from 'lodash/isNull'
import { history } from 'config/history' import { history } from 'config/history'
import { client } from 'config/clients' import { client } from 'config/clients'
import { checkCookie } from '../cookie'
const KEY = 'lang' const KEY = 'lang'
@ -15,3 +16,10 @@ export const addLanguageUrlParam = (lang: string, url: string) => {
urlObject.searchParams.set(KEY, lang) urlObject.searchParams.set(KEY, lang)
return urlObject.toString() 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()
}

Loading…
Cancel
Save