refactor(frontend): merge authserver web login

This commit is contained in:
mac
2026-07-15 14:47:42 +08:00
parent 6af511ed0b
commit 81d2a8a60b
23 changed files with 178 additions and 1115 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
const TOKEN_KEY = 'xinfra_token'
const USER_KEY = 'xinfra_user'
const TOKEN_KEY = 'authserver_token'
const USER_KEY = 'authserver_user'
export function getToken(): string | null {
return localStorage.getItem(TOKEN_KEY)
+42
View File
@@ -0,0 +1,42 @@
import { setToken } from '@/utils/auth'
const SSO_LOGIN_PATH = '/auth/api/v1/login/internal-sso'
export function relayState(openApp = ''): string {
const url = new URL(window.location.href)
url.searchParams.delete('sso_token')
url.searchParams.delete('open_app')
if (openApp) {
url.searchParams.set('open_app', openApp)
}
return `${url.pathname}${url.search}${url.hash}` || '/'
}
export function redirectToSSO(openApp = ''): void {
window.location.assign(`${SSO_LOGIN_PATH}?relay_state=${encodeURIComponent(relayState(openApp))}`)
}
export function consumeSSOToken(): string {
const url = new URL(window.location.href)
const token = url.searchParams.get('sso_token') || ''
if (!token) {
return ''
}
setToken(token)
url.searchParams.delete('sso_token')
window.history.replaceState({}, '', `${url.pathname}${url.search}${url.hash}`)
return token
}
export function consumeOpenApp(): string {
const url = new URL(window.location.href)
const openApp = url.searchParams.get('open_app') || ''
if (!openApp) {
return ''
}
url.searchParams.delete('open_app')
window.history.replaceState({}, '', `${url.pathname}${url.search}${url.hash}`)
return openApp
}