修复前端数据缓存错误
This commit is contained in:
parent
2d1cb1546f
commit
1931df4c7f
@ -3,13 +3,14 @@ import { ApiErr } from "@/apis/error";
|
|||||||
import { token } from "@/store/store";
|
import { token } from "@/store/store";
|
||||||
import { useRequest } from "ahooks";
|
import { useRequest } from "ahooks";
|
||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
|
import { useEffect } from "react";
|
||||||
import { useNavigate, Navigate } from "react-router-dom";
|
import { useNavigate, Navigate } from "react-router-dom";
|
||||||
|
|
||||||
|
|
||||||
export default function NeedLogin({ children, needAdmin = false }: { children: JSX.Element, needAdmin?: boolean }) {
|
export default function NeedLogin({ children, needAdmin = false }: { children: JSX.Element, needAdmin?: boolean }) {
|
||||||
const t = useAtomValue(token)
|
const t = useAtomValue(token)
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
useRequest(() => userInfo(t), {
|
const u = useRequest(() => userInfo(t), {
|
||||||
refreshDeps: [t],
|
refreshDeps: [t],
|
||||||
cacheKey: "/api/v1/user" + t,
|
cacheKey: "/api/v1/user" + t,
|
||||||
staleTime: 60000,
|
staleTime: 60000,
|
||||||
@ -18,18 +19,19 @@ export default function NeedLogin({ children, needAdmin = false }: { children: J
|
|||||||
navigate("/login")
|
navigate("/login")
|
||||||
}
|
}
|
||||||
console.warn(e)
|
console.warn(e)
|
||||||
},
|
|
||||||
onSuccess: u => {
|
|
||||||
if (!u) return
|
|
||||||
if (!u.is_admin && needAdmin) {
|
|
||||||
navigate("/login")
|
|
||||||
}
|
|
||||||
if (u.uuid == "") {
|
|
||||||
navigate("/login")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!u.data) return
|
||||||
|
if (!u.data.is_admin && needAdmin) {
|
||||||
|
navigate("/login")
|
||||||
|
}
|
||||||
|
if (u.data.uuid == "") {
|
||||||
|
navigate("/login")
|
||||||
|
}
|
||||||
|
}, [navigate, needAdmin, u.data])
|
||||||
|
|
||||||
if (!localStorage.getItem("token") || localStorage.getItem("token") == '""') {
|
if (!localStorage.getItem("token") || localStorage.getItem("token") == '""') {
|
||||||
return <Navigate to="/login" />
|
return <Navigate to="/login" />
|
||||||
}
|
}
|
||||||
|
@ -46,25 +46,26 @@ export default function SignUp() {
|
|||||||
setDisableEmail(true)
|
setDisableEmail(true)
|
||||||
}, [u.searchParams])
|
}, [u.searchParams])
|
||||||
|
|
||||||
useRequest(getConfig, {
|
const server = useRequest(getConfig, {
|
||||||
cacheKey: "/api/v1/config",
|
cacheKey: "/api/v1/config",
|
||||||
staleTime: 60000,
|
staleTime: 60000,
|
||||||
onError: e => {
|
onError: e => {
|
||||||
console.warn(e)
|
console.warn(e)
|
||||||
setRegErr(String(e))
|
setRegErr(String(e))
|
||||||
},
|
|
||||||
onSuccess: v => {
|
|
||||||
if (!v.NeedEmail) return
|
|
||||||
|
|
||||||
const code = u.searchParams.get("code")
|
|
||||||
if (!code || code == "") {
|
|
||||||
navigate("/register_email")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setCode(code)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (!server.data || !server.data.NeedEmail) return
|
||||||
|
|
||||||
|
const code = u.searchParams.get("code")
|
||||||
|
if (!code || code == "") {
|
||||||
|
navigate("/register_email")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setCode(code)
|
||||||
|
}, [server.data, u.searchParams, navigate])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const checkList = React.useRef<Map<string, refType>>(new Map<string, refType>())
|
const checkList = React.useRef<Map<string, refType>>(new Map<string, refType>())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user