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 { 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<HTMLFormElement>(null)
const {
email,
error: formError,
@ -134,6 +134,6 @@ export const useLoginForm = () => {
response_type,
scope,
setIsRecoveryPopupOpen,
url,
url: addAccessTokenToUrl(url),
}
}

@ -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),

@ -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()

@ -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 = () => {
</SubscriptionGuard>
</Main>
{
(profile?.tournament.id === 131 || profile?.tournament.id === 2032)
user && (profile?.tournament.id === 131 || profile?.tournament.id === 2032)
&& <FavouriteTeamPopup />
}
</PageWrapper>

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

@ -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,
}
}

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

@ -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]
}

@ -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()
}

Loading…
Cancel
Save