mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-19 19:04:23 +08:00
chore: 完成项目多维度优化与功能迭代
本次提交包含多项改进: 1. 新增Vitest测试配置与相关测试用例 2. 完善Deep Link监听与OAuth回调支持 3. 修复并优化多个React组件的依赖与性能 4. 更新后端API域名与端点地址 5. 优化KV存储服务实现与类型定义 6. 调整用户信息展示与权限相关逻辑 7. 重构部分业务逻辑,使用useCallback优化性能 8. 更新依赖包与Cargo.lock依赖版本
This commit is contained in:
@@ -1,35 +1,44 @@
|
||||
import { useEffect } from "react"
|
||||
import { useEffect, useState } from "react"
|
||||
import { useSearchParams, useNavigate } from "react-router-dom"
|
||||
import { sectlAuth } from "../../services/sectlAuth"
|
||||
|
||||
export function OAuthCallback() {
|
||||
const [searchParams] = useSearchParams()
|
||||
const navigate = useNavigate()
|
||||
const [status, setStatus] = useState<"processing" | "success" | "error">("processing")
|
||||
const [errorMessage, setErrorMessage] = useState<string>("")
|
||||
|
||||
useEffect(() => {
|
||||
const code = searchParams.get("code")
|
||||
const error = searchParams.get("error")
|
||||
const errorDescription = searchParams.get("error_description")
|
||||
const handleCallback = async () => {
|
||||
const code = searchParams.get("code")
|
||||
const error = searchParams.get("error")
|
||||
const errorDescription = searchParams.get("error_description")
|
||||
|
||||
if (error) {
|
||||
window.postMessage(
|
||||
{
|
||||
error: errorDescription || error,
|
||||
},
|
||||
window.location.origin
|
||||
)
|
||||
navigate("/")
|
||||
return
|
||||
if (error) {
|
||||
setStatus("error")
|
||||
setErrorMessage(errorDescription || error)
|
||||
setTimeout(() => navigate("/"), 3000)
|
||||
return
|
||||
}
|
||||
|
||||
if (code) {
|
||||
try {
|
||||
await sectlAuth.exchangeCodeForToken(code)
|
||||
setStatus("success")
|
||||
setTimeout(() => navigate("/"), 1500)
|
||||
} catch (err: any) {
|
||||
setStatus("error")
|
||||
setErrorMessage(err.message || "Token 交换失败")
|
||||
setTimeout(() => navigate("/"), 3000)
|
||||
}
|
||||
} else {
|
||||
setStatus("error")
|
||||
setErrorMessage("未收到授权码")
|
||||
setTimeout(() => navigate("/"), 3000)
|
||||
}
|
||||
}
|
||||
|
||||
if (code) {
|
||||
window.postMessage(
|
||||
{
|
||||
code,
|
||||
},
|
||||
window.location.origin
|
||||
)
|
||||
navigate("/")
|
||||
}
|
||||
handleCallback()
|
||||
}, [searchParams, navigate])
|
||||
|
||||
return (
|
||||
@@ -43,7 +52,18 @@ export function OAuthCallback() {
|
||||
color: "var(--ss-text-main)",
|
||||
}}
|
||||
>
|
||||
<div>正在处理登录...</div>
|
||||
<div style={{ textAlign: "center" }}>
|
||||
{status === "processing" && <div>正在处理登录...</div>}
|
||||
{status === "success" && <div>登录成功,正在跳转...</div>}
|
||||
{status === "error" && (
|
||||
<div>
|
||||
<div style={{ color: "#ff4d4f" }}>登录失败</div>
|
||||
<div style={{ fontSize: "12px", marginTop: "8px", color: "var(--ss-text-secondary)" }}>
|
||||
{errorMessage}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user