移动端sso

This commit is contained in:
biss committed 2026-08-15 16:37:10 +08:00
1 parent 18151fda81
commit f08cd94924
10 files changed
+155 -11

No files matched your search

+6 -2
View File
@@ -3,6 +3,8 @@ import { onMounted, reactive, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import http, { apiErrorMessage } from '../api/http'
import { useAuthStore } from '../stores/auth'
import { isNativeApp } from '../auth/session'
import { openSsoLogin } from '../services/nativeAppLinks'
const route = useRoute()
const router = useRouter()
@@ -43,8 +45,10 @@ async function loadAccount() {
async function startBinding() {
actionLoading.value = true
try {
const { data } = await http.post('/auth/sso/prepare-binding')
window.location.assign(String(data.loginUrl))
const { data } = await http.post('/auth/sso/prepare-binding', null, {
params: { nativeApp: isNativeApp() },
})
await openSsoLogin(String(data.loginUrl))
} catch (error) {
ElMessage.error(apiErrorMessage(error))
actionLoading.value = false
+11 -4
View File
@@ -4,6 +4,8 @@ import { useRoute, useRouter } from 'vue-router'
import { apiErrorMessage } from '../api/http'
import { useAuthStore } from '../stores/auth'
import http from '../api/http'
import { isNativeApp } from '../auth/session'
import { openSsoLogin } from '../services/nativeAppLinks'
const route = useRoute()
const router = useRouter()
@@ -28,13 +30,18 @@ async function submit() {
}
}
function startSso() {
async function startSso() {
ssoLoading.value = true
const apiBaseUrl = String(import.meta.env.VITE_API_BASE_URL ?? '/api').replace(/\/$/, '')
const redirect = String(route.query.redirect ?? '/dashboard')
window.location.assign(
`${apiBaseUrl}/auth/sso/login?returnUrl=${encodeURIComponent(redirect)}`,
)
try {
await openSsoLogin(
`${apiBaseUrl}/auth/sso/login?returnUrl=${encodeURIComponent(redirect)}&nativeApp=${isNativeApp()}`,
)
} catch (error) {
ssoLoading.value = false
ElMessage.error(apiErrorMessage(error))
}
}
const ssoErrors: Record<string, string> = {