fix: 优化登录流程和余额查询逻辑

- 添加 fetchBalanceWithToken 支持登录时直接传入 token 查询余额
- AuthProvider 会话加载改为同步方式避免时序问题
- 添加调试日志便于排查问题
This commit is contained in:
XiaoFeng
2026-01-13 20:06:42 +08:00
parent 5753e120ba
commit 7d1b8f7e26
4 changed files with 35 additions and 6 deletions

View File

@ -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 接口