完善个人中心页面
This commit is contained in:
@@ -1,16 +1,9 @@
|
||||
import { useEffect, useState } from "react"
|
||||
import { Navigate, useLocation } from "react-router-dom"
|
||||
import { AUTH_EVENT, isAuthed } from "@/api/token"
|
||||
import { useProfileStore } from "@/components/stores/profile"
|
||||
|
||||
export default function AuthGuard({ children }: { children: React.ReactNode }) {
|
||||
const location = useLocation()
|
||||
const [isValid, setIsValid] = useState(isAuthed)
|
||||
|
||||
useEffect(() => {
|
||||
const update = () => setIsValid(isAuthed())
|
||||
window.addEventListener(AUTH_EVENT, update)
|
||||
return () => window.removeEventListener(AUTH_EVENT, update)
|
||||
}, [])
|
||||
const isValid = useProfileStore(state => state.token !== null)
|
||||
|
||||
if (!isValid) {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user