mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-21 11:49:02 +08:00
feat: 顶栏登录信息
This commit is contained in:
@@ -346,6 +346,7 @@ export const Settings: React.FC<{
|
||||
try {
|
||||
await api.oauthClearLoginState()
|
||||
setOAuthUserInfo(null)
|
||||
window.dispatchEvent(new CustomEvent("ss:oauth-user-updated", { detail: { user: null } }))
|
||||
messageApi.success(t("auth.logout"))
|
||||
} catch (error: any) {
|
||||
messageApi.error(error?.message || t("common.error"))
|
||||
@@ -412,6 +413,42 @@ export const Settings: React.FC<{
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const handleOAuthUserUpdated = (event: Event) => {
|
||||
const customEvent = event as CustomEvent<{
|
||||
user?:
|
||||
| {
|
||||
user_id?: string
|
||||
email?: string
|
||||
name?: string
|
||||
github_username?: string
|
||||
permission?: number
|
||||
}
|
||||
| null
|
||||
}>
|
||||
const user = customEvent?.detail?.user
|
||||
if (user?.user_id && user.email && user.name && typeof user.permission === "number") {
|
||||
setOAuthUserInfo({
|
||||
user_id: user.user_id,
|
||||
email: user.email,
|
||||
name: user.name,
|
||||
github_username: user.github_username,
|
||||
permission: user.permission,
|
||||
})
|
||||
} else {
|
||||
setOAuthUserInfo(null)
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("ss:oauth-user-updated", handleOAuthUserUpdated as EventListener)
|
||||
return () => {
|
||||
window.removeEventListener(
|
||||
"ss:oauth-user-updated",
|
||||
handleOAuthUserUpdated as EventListener
|
||||
)
|
||||
}
|
||||
}, [])
|
||||
|
||||
const showLogs = async () => {
|
||||
if (!(window as any).api) return
|
||||
setLogsLoading(true)
|
||||
|
||||
Reference in New Issue
Block a user