Compare commits
3 Commits
8ce9268e76
...
4ac6c4892e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ac6c4892e | ||
|
|
98ea8f2427 | ||
|
|
7c166f7186 |
@@ -219,5 +219,14 @@ module.exports = {
|
|||||||
devMiddleware: {
|
devMiddleware: {
|
||||||
writeToDisk: false,
|
writeToDisk: false,
|
||||||
},
|
},
|
||||||
|
// 代理配置:将 /api 请求代理到后端服务器
|
||||||
|
proxy: {
|
||||||
|
'/api': {
|
||||||
|
target: 'http://49.232.185.254:5001',
|
||||||
|
changeOrigin: true,
|
||||||
|
secure: false,
|
||||||
|
logLevel: 'debug',
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import WechatRegister from './WechatRegister';
|
|||||||
|
|
||||||
// API配置
|
// API配置
|
||||||
const isProduction = process.env.NODE_ENV === 'production';
|
const isProduction = process.env.NODE_ENV === 'production';
|
||||||
const API_BASE_URL = isProduction ? "" : "http://49.232.185.254:5000";
|
const API_BASE_URL = isProduction ? "" : "http://49.232.185.254:5001";
|
||||||
|
|
||||||
// 统一配置对象
|
// 统一配置对象
|
||||||
const AUTH_CONFIG = {
|
const AUTH_CONFIG = {
|
||||||
@@ -54,7 +54,7 @@ const AUTH_CONFIG = {
|
|||||||
// API配置
|
// API配置
|
||||||
api: {
|
api: {
|
||||||
endpoint: '/api/auth/register/phone',
|
endpoint: '/api/auth/register/phone',
|
||||||
purpose: 'register',
|
purpose: 'login', // ⚡ 统一使用 'login' 模式
|
||||||
},
|
},
|
||||||
|
|
||||||
// 功能开关
|
// 功能开关
|
||||||
@@ -159,6 +159,7 @@ export default function AuthFormContent() {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
|
credentials: 'include',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
credential,
|
credential,
|
||||||
type: 'phone',
|
type: 'phone',
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect, useRef, useCallback } from "react";
|
import React, { useState, useEffect, useLayoutEffect, useRef, useCallback } from "react";
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
@@ -14,6 +14,7 @@ import { authService, WECHAT_STATUS, STATUS_MESSAGES } from "../../services/auth
|
|||||||
|
|
||||||
// 配置常量
|
// 配置常量
|
||||||
const POLL_INTERVAL = 2000; // 轮询间隔:2秒
|
const POLL_INTERVAL = 2000; // 轮询间隔:2秒
|
||||||
|
const BACKUP_POLL_INTERVAL = 3000; // 备用轮询间隔:3秒
|
||||||
const QR_CODE_TIMEOUT = 300000; // 二维码超时:5分钟
|
const QR_CODE_TIMEOUT = 300000; // 二维码超时:5分钟
|
||||||
|
|
||||||
export default function WechatRegister() {
|
export default function WechatRegister() {
|
||||||
@@ -22,11 +23,14 @@ export default function WechatRegister() {
|
|||||||
const [wechatSessionId, setWechatSessionId] = useState("");
|
const [wechatSessionId, setWechatSessionId] = useState("");
|
||||||
const [wechatStatus, setWechatStatus] = useState(WECHAT_STATUS.NONE);
|
const [wechatStatus, setWechatStatus] = useState(WECHAT_STATUS.NONE);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [scale, setScale] = useState(1); // iframe 缩放比例
|
||||||
|
|
||||||
// 使用 useRef 管理定时器,避免闭包问题和内存泄漏
|
// 使用 useRef 管理定时器,避免闭包问题和内存泄漏
|
||||||
const pollIntervalRef = useRef(null);
|
const pollIntervalRef = useRef(null);
|
||||||
|
const backupPollIntervalRef = useRef(null); // 备用轮询定时器
|
||||||
const timeoutRef = useRef(null);
|
const timeoutRef = useRef(null);
|
||||||
const isMountedRef = useRef(true); // 追踪组件挂载状态
|
const isMountedRef = useRef(true); // 追踪组件挂载状态
|
||||||
|
const containerRef = useRef(null); // 容器DOM引用
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
@@ -65,6 +69,10 @@ export default function WechatRegister() {
|
|||||||
clearInterval(pollIntervalRef.current);
|
clearInterval(pollIntervalRef.current);
|
||||||
pollIntervalRef.current = null;
|
pollIntervalRef.current = null;
|
||||||
}
|
}
|
||||||
|
if (backupPollIntervalRef.current) {
|
||||||
|
clearInterval(backupPollIntervalRef.current);
|
||||||
|
backupPollIntervalRef.current = null;
|
||||||
|
}
|
||||||
if (timeoutRef.current) {
|
if (timeoutRef.current) {
|
||||||
clearTimeout(timeoutRef.current);
|
clearTimeout(timeoutRef.current);
|
||||||
timeoutRef.current = null;
|
timeoutRef.current = null;
|
||||||
@@ -192,6 +200,7 @@ export default function WechatRegister() {
|
|||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
|
// 生产环境:调用真实 API
|
||||||
const response = await authService.getWechatQRCode();
|
const response = await authService.getWechatQRCode();
|
||||||
|
|
||||||
// 检查组件是否已卸载
|
// 检查组件是否已卸载
|
||||||
@@ -201,13 +210,13 @@ export default function WechatRegister() {
|
|||||||
if (!response) {
|
if (!response) {
|
||||||
throw new Error('服务器无响应');
|
throw new Error('服务器无响应');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response.auth_url || !response.session_id) {
|
if (response.code !== 0) {
|
||||||
throw new Error('获取二维码失败:响应数据不完整');
|
throw new Error('获取二维码失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
setWechatAuthUrl(response.auth_url);
|
setWechatAuthUrl(response.data.auth_url);
|
||||||
setWechatSessionId(response.session_id);
|
setWechatSessionId(response.data.session_id);
|
||||||
setWechatStatus(WECHAT_STATUS.WAITING);
|
setWechatStatus(WECHAT_STATUS.WAITING);
|
||||||
|
|
||||||
// 启动轮询检查扫码状态
|
// 启动轮询检查扫码状态
|
||||||
@@ -236,6 +245,80 @@ export default function WechatRegister() {
|
|||||||
};
|
};
|
||||||
}, [clearTimers]);
|
}, [clearTimers]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备用轮询机制 - 防止丢失状态
|
||||||
|
* 每3秒检查一次,仅在获取到二维码URL且状态为waiting时执行
|
||||||
|
*/
|
||||||
|
useEffect(() => {
|
||||||
|
// 只在有auth_url、session_id且状态为waiting时启动备用轮询
|
||||||
|
if (wechatAuthUrl && wechatSessionId && wechatStatus === WECHAT_STATUS.WAITING) {
|
||||||
|
console.log('备用轮询:启动备用轮询机制');
|
||||||
|
|
||||||
|
backupPollIntervalRef.current = setInterval(() => {
|
||||||
|
try {
|
||||||
|
if (wechatStatus === WECHAT_STATUS.WAITING && isMountedRef.current) {
|
||||||
|
console.log('备用轮询:检查微信状态');
|
||||||
|
// 添加 .catch() 静默处理异步错误,防止被 ErrorBoundary 捕获
|
||||||
|
checkWechatStatus().catch(error => {
|
||||||
|
console.warn('备用轮询检查失败(静默处理):', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// 捕获所有同步错误,防止被 ErrorBoundary 捕获
|
||||||
|
console.warn('备用轮询执行出错(静默处理):', error);
|
||||||
|
}
|
||||||
|
}, BACKUP_POLL_INTERVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理备用轮询
|
||||||
|
return () => {
|
||||||
|
if (backupPollIntervalRef.current) {
|
||||||
|
clearInterval(backupPollIntervalRef.current);
|
||||||
|
backupPollIntervalRef.current = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [wechatAuthUrl, wechatSessionId, wechatStatus, checkWechatStatus]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测量容器尺寸并计算缩放比例
|
||||||
|
*/
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
// 微信授权页面的原始尺寸
|
||||||
|
const ORIGINAL_WIDTH = 600;
|
||||||
|
const ORIGINAL_HEIGHT = 800;
|
||||||
|
|
||||||
|
const calculateScale = () => {
|
||||||
|
if (containerRef.current) {
|
||||||
|
const { width, height } = containerRef.current.getBoundingClientRect();
|
||||||
|
|
||||||
|
// 计算宽高比例,取较小值确保完全适配
|
||||||
|
const scaleX = width / ORIGINAL_WIDTH;
|
||||||
|
const scaleY = height / ORIGINAL_HEIGHT;
|
||||||
|
const newScale = Math.min(scaleX, scaleY, 1.0); // 最大不超过1.0
|
||||||
|
|
||||||
|
// 设置最小缩放比例为0.3,避免过小
|
||||||
|
setScale(Math.max(newScale, 0.3));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 初始计算
|
||||||
|
calculateScale();
|
||||||
|
|
||||||
|
// 使用 ResizeObserver 监听容器尺寸变化
|
||||||
|
const resizeObserver = new ResizeObserver(() => {
|
||||||
|
calculateScale();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (containerRef.current) {
|
||||||
|
resizeObserver.observe(containerRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理
|
||||||
|
return () => {
|
||||||
|
resizeObserver.disconnect();
|
||||||
|
};
|
||||||
|
}, [wechatStatus]); // 当状态变化时重新计算
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 渲染状态提示文本
|
* 渲染状态提示文本
|
||||||
*/
|
*/
|
||||||
@@ -246,96 +329,123 @@ export default function WechatRegister() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Text fontSize="xs" color="gray.500">
|
<Text fontSize="xs" color="gray.500">
|
||||||
{STATUS_MESSAGES[wechatStatus] || STATUS_MESSAGES[WECHAT_STATUS.WAITING]}
|
{STATUS_MESSAGES[wechatStatus]}
|
||||||
</Text>
|
</Text>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VStack spacing={2}>
|
<VStack spacing={2} display="flex" alignItems="center" justifyContent="center">
|
||||||
<Text fontSize="lg" fontWeight="bold" color="gray.700" whiteSpace="nowrap">
|
{wechatStatus === WECHAT_STATUS.WAITING ? (
|
||||||
微信扫一扫
|
<>
|
||||||
</Text>
|
<Text fontSize="lg" fontWeight="bold" color="gray.700" whiteSpace="nowrap">
|
||||||
|
微信扫码
|
||||||
<Box
|
</Text>
|
||||||
position="relative"
|
<Box
|
||||||
minH="120px"
|
ref={containerRef}
|
||||||
display="flex"
|
position="relative"
|
||||||
alignItems="center"
|
width="150px"
|
||||||
justifyContent="center"
|
height="100px"
|
||||||
>
|
maxWidth="100%"
|
||||||
{/* 灰色二维码底图 - 始终显示 */}
|
display="flex"
|
||||||
{wechatStatus === WECHAT_STATUS.WAITING ? (
|
alignItems="center"
|
||||||
<Box position="relative" width="96px" height="96px">
|
justifyContent="center"
|
||||||
|
overflow="hidden"
|
||||||
|
>
|
||||||
<iframe
|
<iframe
|
||||||
src={wechatAuthUrl}
|
src={wechatAuthUrl}
|
||||||
width="96"
|
title="微信扫码登录"
|
||||||
height="96"
|
width="300"
|
||||||
style={{ borderRadius: '8px', border: 'none' }}
|
height="350"
|
||||||
|
style={{
|
||||||
|
borderRadius: '8px',
|
||||||
|
border: 'none',
|
||||||
|
transform: `scale(${scale})`,
|
||||||
|
transformOrigin: 'center center'
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
) : (
|
{/* {renderStatusText()} */}
|
||||||
<Icon as={FaQrcode} w={24} h={24} color="gray.300" />
|
</>
|
||||||
)}
|
) : (
|
||||||
|
<>
|
||||||
|
<Text fontSize="lg" fontWeight="bold" color="gray.700" whiteSpace="nowrap">
|
||||||
|
微信扫码
|
||||||
|
</Text>
|
||||||
|
|
||||||
{/* 加载动画 */}
|
|
||||||
{isLoading && (
|
|
||||||
<Box
|
<Box
|
||||||
position="absolute"
|
position="relative"
|
||||||
top="0"
|
width="150px"
|
||||||
left="0"
|
height="100px"
|
||||||
right="0"
|
maxWidth="100%"
|
||||||
bottom="0"
|
|
||||||
display="flex"
|
display="flex"
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
justifyContent="center"
|
justifyContent="center"
|
||||||
|
overflow="hidden"
|
||||||
>
|
>
|
||||||
<Spinner
|
{/* 灰色二维码底图 - 始终显示 */}
|
||||||
size="lg"
|
<Icon as={FaQrcode} w={24} h={24} color="gray.300" />
|
||||||
color="green.500"
|
|
||||||
thickness="4px"
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* 显示获取/刷新二维码按钮 */}
|
{/* 加载动画 */}
|
||||||
{(wechatStatus === WECHAT_STATUS.NONE || wechatStatus === WECHAT_STATUS.EXPIRED) && (
|
{isLoading && (
|
||||||
<Box
|
<Box
|
||||||
position="absolute"
|
position="absolute"
|
||||||
top="0"
|
top="0"
|
||||||
left="0"
|
left="0"
|
||||||
right="0"
|
right="0"
|
||||||
bottom="0"
|
bottom="0"
|
||||||
display="flex"
|
display="flex"
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
justifyContent="center"
|
justifyContent="center"
|
||||||
bg="rgba(255, 255, 255, 0.3)"
|
|
||||||
backdropFilter="blur(2px)"
|
|
||||||
>
|
|
||||||
<VStack spacing={2}>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
colorScheme="green"
|
|
||||||
size="sm"
|
|
||||||
onClick={getWechatQRCode}
|
|
||||||
isLoading={isLoading}
|
|
||||||
leftIcon={<Icon as={FaQrcode} />}
|
|
||||||
_hover={{ bg: "green.50" }}
|
|
||||||
>
|
>
|
||||||
{wechatStatus === WECHAT_STATUS.EXPIRED ? "点击刷新" : "获取二维码"}
|
<Spinner
|
||||||
</Button>
|
size="lg"
|
||||||
{wechatStatus === WECHAT_STATUS.EXPIRED && (
|
color="green.500"
|
||||||
<Text fontSize="xs" color="gray.500">
|
thickness="4px"
|
||||||
二维码已过期
|
/>
|
||||||
</Text>
|
</Box>
|
||||||
)}
|
)}
|
||||||
</VStack>
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
</Box>
|
|
||||||
|
|
||||||
{/* 扫码状态提示 */}
|
{/* 显示获取/刷新二维码按钮 */}
|
||||||
{renderStatusText()}
|
{(wechatStatus === WECHAT_STATUS.NONE || wechatStatus === WECHAT_STATUS.EXPIRED) && (
|
||||||
|
<Box
|
||||||
|
position="absolute"
|
||||||
|
top="0"
|
||||||
|
left="0"
|
||||||
|
right="0"
|
||||||
|
bottom="0"
|
||||||
|
display="flex"
|
||||||
|
alignItems="center"
|
||||||
|
justifyContent="center"
|
||||||
|
bg="rgba(255, 255, 255, 0.3)"
|
||||||
|
backdropFilter="blur(2px)"
|
||||||
|
>
|
||||||
|
<VStack spacing={2}>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
colorScheme="green"
|
||||||
|
size="sm"
|
||||||
|
onClick={getWechatQRCode}
|
||||||
|
isLoading={isLoading}
|
||||||
|
leftIcon={<Icon as={FaQrcode} />}
|
||||||
|
_hover={{ bg: "green.50" }}
|
||||||
|
>
|
||||||
|
{wechatStatus === WECHAT_STATUS.EXPIRED ? "点击刷新" : "获取二维码"}
|
||||||
|
</Button>
|
||||||
|
{wechatStatus === WECHAT_STATUS.EXPIRED && (
|
||||||
|
<Text fontSize="xs" color="gray.500">
|
||||||
|
二维码已过期
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</VStack>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* 扫码状态提示 */}
|
||||||
|
{/* {renderStatusText()} */}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</VStack>
|
</VStack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,22 +36,10 @@ const ProtectedRoute = ({ children }) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 未登录时显示占位符(弹窗会自动打开)
|
// 未登录时,渲染子组件 + 自动打开弹窗(通过 useEffect)
|
||||||
|
// 弹窗会在 useEffect 中自动触发,页面正常显示
|
||||||
if (!isAuthenticated || !user) {
|
if (!isAuthenticated || !user) {
|
||||||
return (
|
return children;
|
||||||
<Box
|
|
||||||
height="100vh"
|
|
||||||
display="flex"
|
|
||||||
alignItems="center"
|
|
||||||
justifyContent="center"
|
|
||||||
bg="gray.50"
|
|
||||||
>
|
|
||||||
<VStack spacing={4}>
|
|
||||||
<Spinner size="xl" color="blue.500" thickness="4px" />
|
|
||||||
<Text fontSize="lg" color="gray.600">请先登录...</Text>
|
|
||||||
</VStack>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 已登录,渲染子组件
|
// 已登录,渲染子组件
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useToast } from '@chakra-ui/react';
|
|||||||
|
|
||||||
// API基础URL配置
|
// API基础URL配置
|
||||||
const isProduction = process.env.NODE_ENV === 'production';
|
const isProduction = process.env.NODE_ENV === 'production';
|
||||||
const API_BASE_URL = isProduction ? "" : process.env.REACT_APP_API_URL || "http://49.232.185.254:5000";
|
const API_BASE_URL = isProduction ? "" : process.env.REACT_APP_API_URL || "http://49.232.185.254:5001";
|
||||||
|
|
||||||
// 创建认证上下文
|
// 创建认证上下文
|
||||||
const AuthContext = createContext();
|
const AuthContext = createContext();
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export const useAuth = () => {
|
|||||||
// 认证提供者组件
|
// 认证提供者组件
|
||||||
export const AuthProvider = ({ children }) => {
|
export const AuthProvider = ({ children }) => {
|
||||||
const [user, setUser] = useState(null);
|
const [user, setUser] = useState(null);
|
||||||
const [isLoading, setIsLoading] = useState(false); // ⚡ 改为 false,不阻塞首屏渲染
|
const [isLoading, setIsLoading] = useState(true); // ⚡ 串行执行,阻塞渲染直到 Session 检查完成
|
||||||
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
@@ -66,8 +66,10 @@ export const AuthProvider = ({ children }) => {
|
|||||||
// 网络错误或超时,设置为未登录状态
|
// 网络错误或超时,设置为未登录状态
|
||||||
setUser(null);
|
setUser(null);
|
||||||
setIsAuthenticated(false);
|
setIsAuthenticated(false);
|
||||||
|
} finally {
|
||||||
|
// ⚡ Session 检查完成后,停止加载状态
|
||||||
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
// ⚡ 移除 finally 中的 setIsLoading(false),不再阻塞渲染
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ⚡ 初始化时检查Session - 并行执行,不阻塞页面渲染
|
// ⚡ 初始化时检查Session - 并行执行,不阻塞页面渲染
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
// src/contexts/AuthModalContext.js
|
// src/contexts/AuthModalContext.js
|
||||||
import { createContext, useContext, useState, useCallback } from 'react';
|
import { createContext, useContext, useState, useCallback } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { useAuth } from './AuthContext';
|
||||||
|
|
||||||
const AuthModalContext = createContext();
|
const AuthModalContext = createContext();
|
||||||
|
|
||||||
@@ -19,6 +21,9 @@ export const useAuthModal = () => {
|
|||||||
* 管理统一的认证弹窗状态(登录/注册合并)
|
* 管理统一的认证弹窗状态(登录/注册合并)
|
||||||
*/
|
*/
|
||||||
export const AuthModalProvider = ({ children }) => {
|
export const AuthModalProvider = ({ children }) => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { isAuthenticated } = useAuth();
|
||||||
|
|
||||||
// 弹窗状态(统一的认证弹窗)
|
// 弹窗状态(统一的认证弹窗)
|
||||||
const [isAuthModalOpen, setIsAuthModalOpen] = useState(false);
|
const [isAuthModalOpen, setIsAuthModalOpen] = useState(false);
|
||||||
|
|
||||||
@@ -41,12 +46,18 @@ export const AuthModalProvider = ({ children }) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 关闭认证弹窗
|
* 关闭认证弹窗
|
||||||
|
* 如果用户未登录,跳转到首页
|
||||||
*/
|
*/
|
||||||
const closeModal = useCallback(() => {
|
const closeModal = useCallback(() => {
|
||||||
setIsAuthModalOpen(false);
|
setIsAuthModalOpen(false);
|
||||||
setRedirectUrl(null);
|
setRedirectUrl(null);
|
||||||
setOnSuccessCallback(null);
|
setOnSuccessCallback(null);
|
||||||
}, []);
|
|
||||||
|
// ⭐ 如果用户关闭弹窗时仍未登录,跳转到首页
|
||||||
|
if (!isAuthenticated) {
|
||||||
|
navigate('/home');
|
||||||
|
}
|
||||||
|
}, [isAuthenticated, navigate]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录/注册成功处理
|
* 登录/注册成功处理
|
||||||
@@ -62,17 +73,12 @@ export const AuthModalProvider = ({ children }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果有重定向URL,则跳转
|
// ⭐ 登录成功后,只关闭弹窗,留在当前页面(不跳转)
|
||||||
if (redirectUrl) {
|
// 移除了原有的 redirectUrl 跳转逻辑
|
||||||
// 使用 window.location.href 确保完整刷新页面状态
|
setIsAuthModalOpen(false);
|
||||||
setTimeout(() => {
|
setRedirectUrl(null);
|
||||||
window.location.href = redirectUrl;
|
setOnSuccessCallback(null);
|
||||||
}, 500); // 延迟500ms,让用户看到成功提示
|
}, [onSuccessCallback]);
|
||||||
}
|
|
||||||
|
|
||||||
// 关闭弹窗
|
|
||||||
closeModal();
|
|
||||||
}, [onSuccessCallback, redirectUrl, closeModal]);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提供给子组件的上下文值
|
* 提供给子组件的上下文值
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import WechatRegister from "../../../components/Auth/WechatRegister";
|
|||||||
|
|
||||||
// API配置
|
// API配置
|
||||||
const isProduction = process.env.NODE_ENV === 'production';
|
const isProduction = process.env.NODE_ENV === 'production';
|
||||||
const API_BASE_URL = isProduction ? "" : "http://49.232.185.254:5000";
|
const API_BASE_URL = isProduction ? "" : "http://49.232.185.254:5001";
|
||||||
|
|
||||||
export default function SignInIllustration() {
|
export default function SignInIllustration() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -179,6 +179,7 @@ export default function SignInIllustration() {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
|
credentials: 'include',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
credential,
|
credential,
|
||||||
type,
|
type,
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ export default function SettingsPage() {
|
|||||||
try {
|
try {
|
||||||
const API_BASE_URL = process.env.NODE_ENV === 'production'
|
const API_BASE_URL = process.env.NODE_ENV === 'production'
|
||||||
? ""
|
? ""
|
||||||
: process.env.REACT_APP_API_URL || "http://49.232.185.254:5000";
|
: process.env.REACT_APP_API_URL || "http://49.232.185.254:5001";
|
||||||
|
|
||||||
const response = await fetch(`${API_BASE_URL}/api/account/password-status`, {
|
const response = await fetch(`${API_BASE_URL}/api/account/password-status`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@@ -188,7 +188,7 @@ export default function SettingsPage() {
|
|||||||
// 调用后端API修改密码
|
// 调用后端API修改密码
|
||||||
const API_BASE_URL = process.env.NODE_ENV === 'production'
|
const API_BASE_URL = process.env.NODE_ENV === 'production'
|
||||||
? ""
|
? ""
|
||||||
: process.env.REACT_APP_API_URL || "http://49.232.185.254:5000";
|
: process.env.REACT_APP_API_URL || "http://49.232.185.254:5001";
|
||||||
|
|
||||||
const response = await fetch(`${API_BASE_URL}/api/account/change-password`, {
|
const response = await fetch(`${API_BASE_URL}/api/account/change-password`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
Reference in New Issue
Block a user