mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-21 11:49:02 +08:00
chore: 为 SECTL Auth 登录链路添加耗时日志
定位点击登录到浏览器弹出之间约 1 分钟延迟的来源,在前端 (handleOAuthLogin / getAuthorizationUrl) 与 Rust (oauth_start_callback_server) 各步骤加 +Nms 相对耗时日志。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -120,9 +120,16 @@ class SectlAuthService {
|
||||
}
|
||||
|
||||
async getAuthorizationUrl(scope?: string[]): Promise<string> {
|
||||
const t0 = performance.now()
|
||||
const log = (step: string) =>
|
||||
console.log(`[sectlAuth.getAuthorizationUrl] ${step} +${Math.round(performance.now() - t0)}ms`)
|
||||
|
||||
const state = this.generateRandomState()
|
||||
log("after generateRandomState")
|
||||
this.codeVerifier = await generateCodeVerifier()
|
||||
log("after generateCodeVerifier")
|
||||
const codeChallenge = await generateCodeChallenge(this.codeVerifier)
|
||||
log("after generateCodeChallenge")
|
||||
|
||||
// 保存 code_verifier 到 localStorage,以便 deep link 回调时使用
|
||||
localStorage.setItem("sectl_code_verifier", this.codeVerifier)
|
||||
@@ -140,7 +147,9 @@ class SectlAuthService {
|
||||
params.set("scope", scope.join(" "))
|
||||
}
|
||||
|
||||
return `${SECTL_CONFIG.authUrl}/oauth/authorize?${params.toString()}`
|
||||
const url = `${SECTL_CONFIG.authUrl}/oauth/authorize?${params.toString()}`
|
||||
log("done")
|
||||
return url
|
||||
}
|
||||
|
||||
async authorize(scope?: string[]): Promise<TokenData> {
|
||||
|
||||
Reference in New Issue
Block a user