fix: 优化登录流程和余额查询逻辑
- 添加 fetchBalanceWithToken 支持登录时直接传入 token 查询余额 - AuthProvider 会话加载改为同步方式避免时序问题 - 添加调试日志便于排查问题
This commit is contained in:
@ -100,7 +100,18 @@ export async function fetchBalance(): Promise<number | null> {
|
||||
return null;
|
||||
}
|
||||
|
||||
const token = session.accessToken;
|
||||
return await fetchBalanceWithToken(session.accessToken);
|
||||
} catch (error) {
|
||||
console.error('[CreditsService] 查询余额异常:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用指定 token 查询余额(登录过程中使用)
|
||||
*/
|
||||
export async function fetchBalanceWithToken(token: string): Promise<number | null> {
|
||||
try {
|
||||
console.log('[CreditsService] 开始查询余额,token 长度:', token.length);
|
||||
|
||||
// 直接调用 StrangeLoop 的 /api/credit/balance 接口
|
||||
|
||||
Reference in New Issue
Block a user