|
|
@@ -4,34 +4,10 @@ import { history } from 'umi';
|
|
|
import { request } from 'umi';
|
|
|
import { DEFAULT_ENTER_PAGE } from '@/config/settings';
|
|
|
|
|
|
-/**
|
|
|
- * 从 URL 中提取 code 参数
|
|
|
- * 兼容两种 URL 格式:
|
|
|
- * 1. /auth/callback?code=xxx#/login (SSO回调无hash, UmiJS自动补的)
|
|
|
- * 2. /#/auth/callback?code=xxx (SSO回调带hash, 推荐)
|
|
|
- */
|
|
|
-function extractCodeFromUrl(): { code: string | null; error: string | null; errorDesc: string | null } {
|
|
|
- // 优先从 hash 中提取 (推荐格式: /#/auth/callback?code=xxx)
|
|
|
- const hash = window.location.hash;
|
|
|
- if (hash && hash.includes('?')) {
|
|
|
- const hashQuery = hash.split('?')[1] || '';
|
|
|
- const hashParams = new URLSearchParams(hashQuery);
|
|
|
- const code = hashParams.get('code');
|
|
|
- if (code) return { code, error: null, errorDesc: null };
|
|
|
- }
|
|
|
-
|
|
|
- // 从 search 中提取 (兼容格式: /auth/callback?code=xxx#/login)
|
|
|
- const searchParams = new URLSearchParams(window.location.search);
|
|
|
- return {
|
|
|
- code: searchParams.get('code'),
|
|
|
- error: searchParams.get('error'),
|
|
|
- errorDesc: searchParams.get('error_description')
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* SSO 回调页面
|
|
|
* 从 URL 参数中提取 code,调用后端换码接口获取本地 JWT
|
|
|
+ * 使用 history 模式,code 参数直接在 URL search 中
|
|
|
*/
|
|
|
const SSOCallback = () => {
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
@@ -43,7 +19,10 @@ const SSOCallback = () => {
|
|
|
if (processedRef.current) return;
|
|
|
processedRef.current = true;
|
|
|
|
|
|
- const { code, error, errorDesc } = extractCodeFromUrl();
|
|
|
+ const searchParams = new URLSearchParams(window.location.search);
|
|
|
+ const code = searchParams.get('code');
|
|
|
+ const error = searchParams.get('error');
|
|
|
+ const errorDesc = searchParams.get('error_description');
|
|
|
|
|
|
// 检查是否有 SSO 错误
|
|
|
if (error) {
|