feat(auth): add callback, silent renew and logout routes
This commit is contained in:
18
auth/RequireAuth.tsx
Normal file
18
auth/RequireAuth.tsx
Normal file
@ -0,0 +1,18 @@
|
||||
import { PropsWithChildren, useEffect } from 'react'
|
||||
import { useLocation } from 'react-router-dom'
|
||||
import { useAuth } from './AuthProvider'
|
||||
|
||||
|
||||
export function RequireAuth({ children }: PropsWithChildren) {
|
||||
const { isAuthenticated, signIn } = useAuth()
|
||||
const loc = useLocation()
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated) void signIn(loc.pathname + loc.search)
|
||||
}, [isAuthenticated, signIn, loc])
|
||||
|
||||
|
||||
if (!isAuthenticated) return null
|
||||
return <>{children}</>
|
||||
}
|
||||
Reference in New Issue
Block a user