移动端sso
This commit is contained in:
1 parent
18151fda81
commit
f08cd94924
10 files changed
+155
-11
No files matched your search
@@ -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
|
||||
|
||||
@@ -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> = {
|
||||
|
||||
Reference in new issue
Block a user