|
@@ -1,8 +1,9 @@
|
|
|
import { useEffect, useRef, useState } from 'react';
|
|
import { useEffect, useRef, useState } from 'react';
|
|
|
import { Spin, message } from 'antd';
|
|
import { Spin, message } from 'antd';
|
|
|
-import { history } from 'umi';
|
|
|
|
|
|
|
+import { history, useModel } from 'umi';
|
|
|
import { request } from 'umi';
|
|
import { request } from 'umi';
|
|
|
import { DEFAULT_ENTER_PAGE } from '@/config/settings';
|
|
import { DEFAULT_ENTER_PAGE } from '@/config/settings';
|
|
|
|
|
+import { queryCurrentUserState } from '@/services/profile/apis';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* SSO 回调页面
|
|
* SSO 回调页面
|
|
@@ -12,6 +13,7 @@ import { DEFAULT_ENTER_PAGE } from '@/config/settings';
|
|
|
const SSOCallback = () => {
|
|
const SSOCallback = () => {
|
|
|
const [loading, setLoading] = useState(true);
|
|
const [loading, setLoading] = useState(true);
|
|
|
const processedRef = useRef(false);
|
|
const processedRef = useRef(false);
|
|
|
|
|
+ const { setInitialState } = useModel('@@initialState') || {};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
const exchangeCode = async () => {
|
|
const exchangeCode = async () => {
|
|
@@ -51,6 +53,21 @@ const SSOCallback = () => {
|
|
|
}
|
|
}
|
|
|
localStorage.setItem('user', JSON.stringify(result.data.user));
|
|
localStorage.setItem('user', JSON.stringify(result.data.user));
|
|
|
|
|
|
|
|
|
|
+ // 获取用户信息并更新 initialState,避免 onPageChange 跳转登录
|
|
|
|
|
+ try {
|
|
|
|
|
+ const userInfo = await queryCurrentUserState({
|
|
|
|
|
+ skipErrorHandler: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ if (setInitialState) {
|
|
|
|
|
+ setInitialState((prev: any) => ({
|
|
|
|
|
+ ...prev,
|
|
|
|
|
+ currentUser: userInfo,
|
|
|
|
|
+ }));
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ // 获取用户信息失败不影响登录流程,后续请求会处理
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
message.success('登录成功');
|
|
message.success('登录成功');
|
|
|
// 使用 replace 避免后退回到回调页
|
|
// 使用 replace 避免后退回到回调页
|
|
|
history.replace(DEFAULT_ENTER_PAGE.user);
|
|
history.replace(DEFAULT_ENTER_PAGE.user);
|