|
|
@@ -1,10 +1,10 @@
|
|
|
<script setup lang="ts">
|
|
|
import { onMounted, onBeforeUnmount, ref } from 'vue'
|
|
|
import { useRouter } from 'vue-router'
|
|
|
+import { ElMessage } from 'element-plus'
|
|
|
import { Loading, Right, RefreshRight } from '@element-plus/icons-vue'
|
|
|
import { jwtDecode } from 'jwt-decode'
|
|
|
import MockLogin from '../Login.vue'
|
|
|
-import { OAUTH_REDIRECTING_KEY } from '../../http'
|
|
|
import { api } from '../../api'
|
|
|
import {
|
|
|
clearAuthInfo, clearOAuthTemp, consumeOAuthTransaction,
|
|
|
@@ -49,7 +49,6 @@ async function authorize() {
|
|
|
if (cancelled) return
|
|
|
sessionStorage.removeItem('warehouse-auth-paused')
|
|
|
sessionStorage.removeItem('oauth_no_auto_redirect')
|
|
|
- sessionStorage.setItem(OAUTH_REDIRECTING_KEY, '1')
|
|
|
location.assign(url)
|
|
|
} catch (error) {
|
|
|
showError(error)
|
|
|
@@ -58,13 +57,11 @@ async function authorize() {
|
|
|
|
|
|
function handleRetryAuth() {
|
|
|
sessionStorage.removeItem('oauth_no_auto_redirect')
|
|
|
- sessionStorage.removeItem(OAUTH_REDIRECTING_KEY)
|
|
|
authorize()
|
|
|
}
|
|
|
|
|
|
function showError(error: unknown) {
|
|
|
clearOAuthTemp()
|
|
|
- sessionStorage.removeItem(OAUTH_REDIRECTING_KEY)
|
|
|
if (cancelled) return
|
|
|
busy.value = false
|
|
|
failed.value = true
|
|
|
@@ -74,25 +71,29 @@ function showError(error: unknown) {
|
|
|
|
|
|
async function handleCallback(code: string, state: string | null, authError: string | null) {
|
|
|
// 清理 URL 中的 OAuth 临时参数,避免刷新页面重复使用
|
|
|
- const query = new URLSearchParams(location.search)
|
|
|
- for (const key of ['code', 'state', 'error', 'error_description', 'session_state', 'iss']) {
|
|
|
- query.delete(key)
|
|
|
- }
|
|
|
- const remaining = query.toString()
|
|
|
- history.replaceState(history.state, '', `${location.pathname}${remaining ? `?${remaining}` : ''}`)
|
|
|
-
|
|
|
- sessionStorage.removeItem('oauth_no_auto_redirect')
|
|
|
- clearAuthInfo()
|
|
|
-
|
|
|
- const cachedState = getCachedOAuthState()
|
|
|
- if (!state || !cachedState || state !== cachedState) {
|
|
|
- showError(new Error('登录状态校验失败,请点击重试'))
|
|
|
- return
|
|
|
- }
|
|
|
+ // const query = new URLSearchParams(location.search)
|
|
|
+ // for (const key of ['code', 'state', 'error', 'error_description', 'session_state', 'iss']) {
|
|
|
+ // query.delete(key)
|
|
|
+ // }
|
|
|
+ // const remaining = query.toString()
|
|
|
+ // history.replaceState(history.state, '', `${location.pathname}${remaining ? `?${remaining}` : ''}`)
|
|
|
+
|
|
|
+ // sessionStorage.removeItem('oauth_no_auto_redirect')
|
|
|
+ // clearAuthInfo()
|
|
|
+
|
|
|
+ // const cachedState = getCachedOAuthState()
|
|
|
+ // if (!state || !cachedState || state !== cachedState) {
|
|
|
+ // ElMessage.warning('登录状态校验失败,准备重新发起认证')
|
|
|
+ // clearOAuthTemp()
|
|
|
+ // authorize()
|
|
|
+ // return
|
|
|
+ // }
|
|
|
|
|
|
const codeVerifier = getCachedVerifier()
|
|
|
if (!codeVerifier) {
|
|
|
- showError(new Error('登录会话已失效,请点击重试'))
|
|
|
+ ElMessage.warning('登录会话已失效,准备重新发起认证')
|
|
|
+ clearOAuthTemp()
|
|
|
+ authorize()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -135,7 +136,6 @@ async function handleCallback(code: string, state: string | null, authError: str
|
|
|
})
|
|
|
|
|
|
clearOAuthTemp()
|
|
|
- sessionStorage.removeItem(OAUTH_REDIRECTING_KEY)
|
|
|
await router.replace('/dashboard')
|
|
|
} catch (error) {
|
|
|
showError(error)
|
|
|
@@ -169,8 +169,6 @@ onMounted(async () => {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if (sessionStorage.getItem(OAUTH_REDIRECTING_KEY) === '1') return
|
|
|
-
|
|
|
await authorize()
|
|
|
})
|
|
|
</script>
|