|
@@ -2,7 +2,7 @@ import React, { useEffect } from 'react';
|
|
|
|
|
|
|
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
|
|
|
|
|
|
|
-import { setToken } from '@/utils/authUtils';
|
|
|
|
|
|
|
+import { removeToken, setToken } from '@/utils/authUtils';
|
|
|
import { decryptUrlParams } from '@/utils/requestCrypto';
|
|
import { decryptUrlParams } from '@/utils/requestCrypto';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -12,8 +12,10 @@ import { decryptUrlParams } from '@/utils/requestCrypto';
|
|
|
*/
|
|
*/
|
|
|
const decryptRedirectParams = async (
|
|
const decryptRedirectParams = async (
|
|
|
_encryptedData: string
|
|
_encryptedData: string
|
|
|
-): Promise<{ userConfig: API.UserInfo; redirectPath: string } | null> => {
|
|
|
|
|
- return decryptUrlParams<{ userConfig: API.UserInfo; redirectPath: string }>(_encryptedData);
|
|
|
|
|
|
|
+): Promise<{ accessToken: string; expireTime: number; redirectPath: string } | null> => {
|
|
|
|
|
+ return decryptUrlParams<{ accessToken: string; expireTime: number; redirectPath: string }>(
|
|
|
|
|
+ _encryptedData
|
|
|
|
|
+ );
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const Redirect: React.FC = () => {
|
|
const Redirect: React.FC = () => {
|
|
@@ -22,7 +24,7 @@ const Redirect: React.FC = () => {
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
const redirectParam = searchParams.get('d');
|
|
const redirectParam = searchParams.get('d');
|
|
|
- console.log('redirectParam', redirectParam);
|
|
|
|
|
|
|
+ console.log('🚀 ~ Redirect ~ redirectParam:', redirectParam);
|
|
|
|
|
|
|
|
// 如果没有重定向参数,默认跳转到 home 页
|
|
// 如果没有重定向参数,默认跳转到 home 页
|
|
|
if (!redirectParam) {
|
|
if (!redirectParam) {
|
|
@@ -35,20 +37,19 @@ const Redirect: React.FC = () => {
|
|
|
try {
|
|
try {
|
|
|
// 解密重定向参数
|
|
// 解密重定向参数
|
|
|
const decryptedData = await decryptRedirectParams(redirectParam);
|
|
const decryptedData = await decryptRedirectParams(redirectParam);
|
|
|
-
|
|
|
|
|
- console.log('decryptedData', decryptedData);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ console.log('🚀 ~ handleRedirect ~ decryptedData:', decryptedData);
|
|
|
if (!decryptedData) {
|
|
if (!decryptedData) {
|
|
|
// 解密失败,跳转到 home 页
|
|
// 解密失败,跳转到 home 页
|
|
|
navigate('/home', { replace: true });
|
|
navigate('/home', { replace: true });
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const { userConfig, redirectPath } = decryptedData;
|
|
|
|
|
|
|
+ const { accessToken, expireTime, redirectPath } = decryptedData;
|
|
|
|
|
|
|
|
// 保存用户信息到 localStorage
|
|
// 保存用户信息到 localStorage
|
|
|
- if (userConfig) {
|
|
|
|
|
- setToken(userConfig);
|
|
|
|
|
|
|
+ if (accessToken) {
|
|
|
|
|
+ removeToken(); // 删除旧的 token
|
|
|
|
|
+ setToken({ accessToken, accessExpires: expireTime }); // 设置新的 token
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 跳转到指定路由
|
|
// 跳转到指定路由
|