refresh user

This commit is contained in:
john 2025-05-19 09:23:15 +02:00
parent 57e56dc33d
commit 17c9885ccc
6 changed files with 127 additions and 20 deletions

View file

@ -0,0 +1,27 @@
import { PropsWithChildren, useEffect, useRef } from 'react'
import { AuthService } from '../authService.ts'
import { useUser } from '../../user/userStore.ts'
interface RefreshUserProps {
authService: AuthService
}
export default function RefreshUser({
authService,
children,
}: PropsWithChildren<RefreshUserProps>) {
const { user } = useUser()
const didRefresh = useRef(false)
useEffect(() => {
const timeoutId = setTimeout(async () => {
if (didRefresh.current) return
if (user == null) return
didRefresh.current = true
await authService.refreshUser(user.userId)
})
return () => clearTimeout(timeoutId)
}, [authService, user])
return <>{children}</>
}