fix: 防止 StrictMode 双重调用导致 jumpToken 重复消费
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
kkfluous
2026-04-02 15:59:11 +08:00
parent f66049dcbc
commit a7ec5ba7b0

View File

@@ -12,11 +12,16 @@ export default function AuthProvider({ children }: { children: ReactNode }) {
error: null, error: null,
}); });
const tokenRef = useRef<string | null>(null); const tokenRef = useRef<string | null>(null);
const authStarted = useRef(false);
useEffect(() => { useEffect(() => {
// 设置全局 token getter // 设置全局 token getter
setTokenGetter(() => tokenRef.current); setTokenGetter(() => tokenRef.current);
// 防止 StrictMode 双重调用jumpToken 一次性使用)
if (authStarted.current) return;
authStarted.current = true;
// 监听 401 事件 // 监听 401 事件
const onUnauthorized = () => { const onUnauthorized = () => {
tokenRef.current = null; tokenRef.current = null;