pref:点击手机登陆后日志优化
This commit is contained in:
@@ -322,16 +322,6 @@ export default function AuthFormContent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (response.ok && data.success) {
|
if (response.ok && data.success) {
|
||||||
// ⚡ Mock 模式:先在前端侧写入 localStorage,确保时序正确
|
|
||||||
if (process.env.REACT_APP_ENABLE_MOCK === 'true' && data.user) {
|
|
||||||
setCurrentUser(data.user);
|
|
||||||
logger.debug('AuthFormContent', '前端侧设置当前用户(Mock模式)', {
|
|
||||||
userId: data.user?.id,
|
|
||||||
phone: data.user?.phone,
|
|
||||||
mockMode: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新session
|
// 更新session
|
||||||
await checkSession();
|
await checkSession();
|
||||||
|
|
||||||
|
|||||||
@@ -69,18 +69,20 @@ export const useSubscription = () => {
|
|||||||
const error = useSelector(selectSubscriptionError);
|
const error = useSelector(selectSubscriptionError);
|
||||||
const isSubscriptionModalOpen = useSelector(selectSubscriptionModalOpen);
|
const isSubscriptionModalOpen = useSelector(selectSubscriptionModalOpen);
|
||||||
|
|
||||||
// 自动加载订阅信息
|
// 自动加载订阅信息(带防重复逻辑)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isAuthenticated && user) {
|
if (isAuthenticated && user) {
|
||||||
// 用户已登录,加载订阅信息
|
// 只在没有数据且未在加载时才请求,避免多个组件重复调用
|
||||||
dispatch(fetchSubscriptionInfo());
|
if (!subscriptionInfo.type && !loading) {
|
||||||
logger.debug('useSubscription', '加载订阅信息', { userId: user.id });
|
dispatch(fetchSubscriptionInfo());
|
||||||
|
logger.debug('useSubscription', '加载订阅信息', { userId: user.id });
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 用户未登录,重置为免费版
|
// 用户未登录,重置为免费版
|
||||||
dispatch(resetToFree());
|
dispatch(resetToFree());
|
||||||
logger.debug('useSubscription', '用户未登录,重置为免费版');
|
|
||||||
}
|
}
|
||||||
}, [isAuthenticated, user, dispatch]);
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [isAuthenticated, user?.id, dispatch]);
|
||||||
|
|
||||||
// 获取订阅级别数值
|
// 获取订阅级别数值
|
||||||
const getSubscriptionLevel = (type = null) => {
|
const getSubscriptionLevel = (type = null) => {
|
||||||
|
|||||||
@@ -102,7 +102,6 @@ export function setCurrentUser(user) {
|
|||||||
subscription_days_left: user.subscription_days_left || 0
|
subscription_days_left: user.subscription_days_left || 0
|
||||||
};
|
};
|
||||||
localStorage.setItem('mock_current_user', JSON.stringify(normalizedUser));
|
localStorage.setItem('mock_current_user', JSON.stringify(normalizedUser));
|
||||||
console.log('[Mock State] 设置当前登录用户:', normalizedUser);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -613,14 +613,6 @@ export const accountHandlers = [
|
|||||||
end_date: currentUser.subscription_end_date || null
|
end_date: currentUser.subscription_end_date || null
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('[Mock API] 获取当前订阅详情:', {
|
|
||||||
user_id: currentUser.id,
|
|
||||||
phone: currentUser.phone,
|
|
||||||
subscription_type: userSubscriptionType,
|
|
||||||
subscription_status: subscriptionDetails.status,
|
|
||||||
days_left: subscriptionDetails.days_left
|
|
||||||
});
|
|
||||||
|
|
||||||
return HttpResponse.json({
|
return HttpResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
data: subscriptionDetails
|
data: subscriptionDetails
|
||||||
|
|||||||
@@ -127,8 +127,6 @@ export const authHandlers = [
|
|||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const { credential, verification_code, login_type } = body;
|
const { credential, verification_code, login_type } = body;
|
||||||
|
|
||||||
console.log('[Mock] 验证码登录:', { credential, verification_code, login_type });
|
|
||||||
|
|
||||||
// 验证验证码
|
// 验证验证码
|
||||||
const storedCode = mockVerificationCodes.get(credential);
|
const storedCode = mockVerificationCodes.get(credential);
|
||||||
if (!storedCode) {
|
if (!storedCode) {
|
||||||
@@ -180,11 +178,8 @@ export const authHandlers = [
|
|||||||
subscription_days_left: 0
|
subscription_days_left: 0
|
||||||
};
|
};
|
||||||
mockUsers[credential] = user;
|
mockUsers[credential] = user;
|
||||||
console.log('[Mock] 创建新用户:', user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[Mock] 登录成功:', user);
|
|
||||||
|
|
||||||
// 设置当前登录用户
|
// 设置当前登录用户
|
||||||
setCurrentUser(user);
|
setCurrentUser(user);
|
||||||
|
|
||||||
@@ -362,8 +357,6 @@ export const authHandlers = [
|
|||||||
// 获取当前登录用户
|
// 获取当前登录用户
|
||||||
const currentUser = getCurrentUser();
|
const currentUser = getCurrentUser();
|
||||||
|
|
||||||
console.log('[Mock] 检查 Session:', currentUser);
|
|
||||||
|
|
||||||
if (currentUser) {
|
if (currentUser) {
|
||||||
return HttpResponse.json({
|
return HttpResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
@@ -386,8 +379,6 @@ export const authHandlers = [
|
|||||||
// 获取当前登录用户
|
// 获取当前登录用户
|
||||||
const currentUser = getCurrentUser();
|
const currentUser = getCurrentUser();
|
||||||
|
|
||||||
console.log('[Mock] 检查 Session (旧端点):', currentUser);
|
|
||||||
|
|
||||||
if (currentUser) {
|
if (currentUser) {
|
||||||
return HttpResponse.json({
|
return HttpResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user