update pay function

This commit is contained in:
2025-11-22 08:57:37 +08:00
parent 990ca3663e
commit e778742590
210 changed files with 8236 additions and 5345 deletions

View File

@@ -0,0 +1,49 @@
// hooks/useAuth.tsx - React Hook 封装认证逻辑
'use client';
import { useState, useEffect } from 'react';
import { checkAuth, AuthInfo } from '../lib/auth';
export function useAuth() {
const [authInfo, setAuthInfo] = useState<AuthInfo>({
isAuthenticated: false,
});
const [loading, setLoading] = useState(true);
useEffect(() => {
// 组件挂载时检查认证状态
const verifyAuth = async () => {
try {
const info = await checkAuth();
setAuthInfo(info);
} catch (error) {
console.error('Auth verification failed:', error);
setAuthInfo({
isAuthenticated: false,
message: '认证检查失败',
});
} finally {
setLoading(false);
}
};
verifyAuth();
// 可选:定期检查认证状态
const interval = setInterval(verifyAuth, 5 * 60 * 1000); // 每5分钟
return () => clearInterval(interval);
}, []);
return {
...authInfo,
loading,
refresh: async () => {
setLoading(true);
const info = await checkAuth();
setAuthInfo(info);
setLoading(false);
return info;
},
};
}