refresh user
This commit is contained in:
parent
57e56dc33d
commit
17c9885ccc
6 changed files with 127 additions and 20 deletions
27
src/app/auth/components/RefreshUser.tsx
Normal file
27
src/app/auth/components/RefreshUser.tsx
Normal 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}</>
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue