chore: 为 SECTL Auth 登录链路添加耗时日志

定位点击登录到浏览器弹出之间约 1 分钟延迟的来源,在前端
(handleOAuthLogin / getAuthorizationUrl) 与 Rust (oauth_start_callback_server)
各步骤加 +Nms 相对耗时日志。

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
JSR
2026-07-05 18:44:59 +08:00
parent e40ba986b2
commit b46acd7581
3 changed files with 46 additions and 4 deletions
+12
View File
@@ -127,12 +127,18 @@ export function OAuthLogin({ visible, onClose, onSuccess }: OAuthLoginProps) {
}
setLoading(true)
const t0 = performance.now()
const log = (step: string) =>
console.log(`[OAuthLogin] ${step} +${Math.round(performance.now() - t0)}ms`)
log("handleOAuthLogin start")
try {
// 启动本地 HTTP 回调服务器 (端口 51267,被占用则强杀已有进程)
const api = (window as any).api
if (api && typeof api.oauthStartCallbackServer === "function") {
log("before oauthStartCallbackServer")
const res = await api.oauthStartCallbackServer()
log(`after oauthStartCallbackServer success=${res?.success}`)
if (!res?.success) {
throw new Error(res?.message || "启动回调服务器失败")
}
@@ -142,19 +148,25 @@ export function OAuthLogin({ visible, onClose, onSuccess }: OAuthLoginProps) {
}
}
log("before getAuthorizationUrl")
const authUrl = await sectlAuth.getAuthorizationUrl()
log(`after getAuthorizationUrl url=${authUrl.slice(0, 60)}...`)
// 使用 Tauri shell 打开系统浏览器
log("before open(authUrl)")
await open(authUrl)
log("after open(authUrl)")
// 设置超时
setTimeout(() => {
if (loading && !completedRef.current) {
log("login timeout, stopping callback server")
stopCallbackServer()
setLoading(false)
message.warning("登录超时,请重试")
}
}, 300000)
} catch (error: any) {
log(`handleOAuthLogin error: ${error?.message}`)
message.error(error.message || "登录失败")
await stopCallbackServer()
setLoading(false)