Correction mise à jour jeton authentification
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useGame, useUpdateGameState, useUpdateMoney } from '@/hooks/useGame'
|
||||
import { useDownloadTrains } from '@/hooks/useTrain'
|
||||
import { isAuthValid } from '@/utils/features/auth/authSlice'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { ReactNode, useEffect } from 'react'
|
||||
|
||||
@ -12,11 +13,11 @@ export default function GameProvider({ children }: { children: ReactNode }) {
|
||||
const downloadTrains = useDownloadTrains()
|
||||
|
||||
const gameQuery = useQuery({
|
||||
queryKey: ['get-game'],
|
||||
queryKey: ['get-game', auth.token],
|
||||
queryFn: () => fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/game/`, {
|
||||
headers: { "Authorization": `Bearer ${auth.token}` }}
|
||||
).then(resp => resp.json()),
|
||||
enabled: auth.loggedIn,
|
||||
enabled: isAuthValid(auth),
|
||||
refetchInterval: 5000,
|
||||
})
|
||||
useEffect(() => {
|
||||
@ -25,11 +26,11 @@ export default function GameProvider({ children }: { children: ReactNode }) {
|
||||
}, [gameQuery.status, gameQuery.dataUpdatedAt])
|
||||
|
||||
const playerQuery = useQuery({
|
||||
queryKey: ['get-player', game.playerId],
|
||||
queryKey: ['get-player', game.playerId, auth.token],
|
||||
queryFn: () => fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/players/${game.playerId}/`, {
|
||||
headers: { "Authorization": `Bearer ${auth.token}` }}
|
||||
).then(resp => resp.json()),
|
||||
enabled: auth.loggedIn && !!game.playerId,
|
||||
enabled: isAuthValid(auth) && !!game.playerId,
|
||||
refetchInterval: 5000,
|
||||
})
|
||||
useEffect(() => {
|
||||
@ -38,15 +39,15 @@ export default function GameProvider({ children }: { children: ReactNode }) {
|
||||
}, [playerQuery.status, playerQuery.dataUpdatedAt])
|
||||
|
||||
const trainsQuery = useQuery({
|
||||
queryKey: ['get-trains'],
|
||||
queryKey: ['get-trains', auth.token],
|
||||
queryFn: () => fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/trains/`, {
|
||||
headers: { "Authorization": `Bearer ${auth.token}` }}
|
||||
).then(resp => resp.json()),
|
||||
enabled: auth.loggedIn,
|
||||
enabled: isAuthValid(auth),
|
||||
refetchInterval: 5000,
|
||||
})
|
||||
useEffect(() => {
|
||||
if (trainsQuery.isSuccess && trainsQuery.data)
|
||||
if (trainsQuery.isSuccess && trainsQuery.data && trainsQuery)
|
||||
downloadTrains(trainsQuery.data)
|
||||
}, [trainsQuery.status, trainsQuery.dataUpdatedAt])
|
||||
|
||||
|
Reference in New Issue
Block a user