sso修复

This commit is contained in:
biss committed 2026-08-23 22:41:02 +08:00
1 parent 76b26a49a8
commit d95ff27ee4
7 files changed
+104 -37

No files matched your search

+25 -8
View File
@@ -4,21 +4,38 @@ import { Capacitor } from '@capacitor/core'
import type { Router } from 'vue-router'
const ssoPaths = new Set(['/sso/callback', '/sso/bind'])
const nativeSsoStateKey = 'jiaowu_native_sso_state'
export function beginNativeSsoLogin() {
if (!Capacitor.isNativePlatform()) return null
const bytes = crypto.getRandomValues(new Uint8Array(32))
const state = Array.from(bytes, byte => byte.toString(16).padStart(2, '0')).join('')
localStorage.setItem(nativeSsoStateKey, state)
return state
}
export function nativeSsoLoginState() {
return Capacitor.isNativePlatform() ? localStorage.getItem(nativeSsoStateKey) : null
}
export function clearNativeSsoLoginState() {
localStorage.removeItem(nativeSsoStateKey)
}
function appLinkRoute(url: string) {
try {
const target = new URL(url)
if (target.protocol === 'mingxu:' && target.host === 'open' && ssoPaths.has(target.pathname)) {
return target.pathname + target.search + target.hash
}
const publicBase = new URL(
String(import.meta.env.VITE_PUBLIC_BASE_URL ?? location.origin),
)
if (
target.protocol !== 'https:' ||
target.origin !== publicBase.origin ||
!ssoPaths.has(target.pathname)
) {
return null
}
return target.pathname + target.search + target.hash
return target.protocol === 'https:' &&
target.origin === publicBase.origin &&
ssoPaths.has(target.pathname)
? target.pathname + target.search + target.hash
: null
} catch {
return null
}