forked from 77media/video-flow
修复 localstorage安全操作
This commit is contained in:
parent
4b33619c20
commit
9e52b1c816
@ -167,7 +167,7 @@ export default function CallbackModal({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const userId = JSON.parse(localStorage.getItem('currentUser') || '{}').id
|
const userId = typeof window !== 'undefined' ? JSON.parse(localStorage.getItem('currentUser') || '{}').id : 0
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (paymentType === 'subscription') {
|
if (paymentType === 'subscription') {
|
||||||
|
|||||||
@ -7,7 +7,8 @@ import { Drawer } from 'antd';
|
|||||||
import { fetchTabsByCode, HomeTabItem } from '@/api/serversetting';
|
import { fetchTabsByCode, HomeTabItem } from '@/api/serversetting';
|
||||||
import { getSigninStatus } from '@/api/signin';
|
import { getSigninStatus } from '@/api/signin';
|
||||||
import { getCurrentUser, isAuthenticated, logoutUser } from '@/lib/auth';
|
import { getCurrentUser, isAuthenticated, logoutUser } from '@/lib/auth';
|
||||||
import { getUserSubscriptionInfo, createPortalSession, redirectToPortal } from '@/lib/stripe';
|
import { getUserSubscriptionInfo } from '@/lib/stripe';
|
||||||
|
import { trackEvent } from '@/utils/analytics';
|
||||||
import { GradientText } from '@/components/ui/gradient-text';
|
import { GradientText } from '@/components/ui/gradient-text';
|
||||||
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog';
|
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog';
|
||||||
import SigninBox from './signin-box';
|
import SigninBox from './signin-box';
|
||||||
@ -184,13 +185,42 @@ export default function H5TopBar({ onSelectHomeTab }: H5TopBarProps) {
|
|||||||
if (!user?.id) return;
|
if (!user?.id) return;
|
||||||
setIsManagingSubscription(true);
|
setIsManagingSubscription(true);
|
||||||
try {
|
try {
|
||||||
const response = await createPortalSession({
|
// 获取用户当前订阅信息
|
||||||
user_id: String(user.id),
|
const response = await getUserSubscriptionInfo(String(user.id));
|
||||||
return_url: window.location.origin + '/dashboard',
|
if (!response?.successful || !response?.data) {
|
||||||
});
|
throw new Error('Failed to get subscription info');
|
||||||
if (response.successful && response.data?.portal_url) {
|
|
||||||
redirectToPortal(response.data.portal_url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currentPlan = response.data.plan_name;
|
||||||
|
const billingType = 'month'; // 默认使用月付,用户可以在pricing页面切换
|
||||||
|
|
||||||
|
// 跟踪订阅管理按钮点击事件
|
||||||
|
trackEvent('subscription_manage_click', {
|
||||||
|
event_category: 'subscription',
|
||||||
|
event_label: 'manage_subscription',
|
||||||
|
custom_parameters: {
|
||||||
|
current_plan: currentPlan,
|
||||||
|
billing_type: billingType,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 复用pricing页面的跳转方案:构建pay-redirect URL
|
||||||
|
const url = `/pay-redirect?type=subscription&plan=${encodeURIComponent(currentPlan)}&billing=${encodeURIComponent(billingType)}`;
|
||||||
|
const win = window.open(url, '_blank');
|
||||||
|
|
||||||
|
// 通知当前窗口等待支付(显示loading模态框)
|
||||||
|
window.postMessage({
|
||||||
|
type: 'waiting-payment',
|
||||||
|
paymentType: 'subscription',
|
||||||
|
}, '*');
|
||||||
|
|
||||||
|
if (!win) {
|
||||||
|
throw new Error('Unable to open redirect window, please check popup settings');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to manage subscription:', error);
|
||||||
|
// 如果出错,回退到pricing页面
|
||||||
|
router.push('/pricing');
|
||||||
} finally {
|
} finally {
|
||||||
setIsManagingSubscription(false);
|
setIsManagingSubscription(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user