fix: guard dulupay checkout for guests
This commit is contained in:
parent
2108d06715
commit
7e0f482bad
@ -72,7 +72,7 @@ async function NewChatPage() {
|
||||
}
|
||||
: null
|
||||
}
|
||||
isAuthenticated={Boolean(session?.user)}
|
||||
isAuthenticated={Boolean(session?.user && session.user.type !== "guest")}
|
||||
siteName={siteSettings.siteName || "AI Chatbot"}
|
||||
siteLogo={siteSettings.siteLogo || ""}
|
||||
siteLogoDark={siteSettings.siteLogoDark || ""}
|
||||
|
||||
@ -32,8 +32,8 @@ function buildOutTradeNo() {
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
if (!session?.user?.id || session.user.type === "guest") {
|
||||
return NextResponse.json({ error: "请先登录正式账号后再充值" }, { status: 401 });
|
||||
}
|
||||
|
||||
const body = createSchema.parse(await request.json());
|
||||
|
||||
@ -1147,7 +1147,7 @@ export function LovartHome({
|
||||
};
|
||||
|
||||
const handleCreateDulupayOrder = async (packageId: string) => {
|
||||
if (!isAuthenticated) {
|
||||
if (!isAuthenticated || user?.type === "guest") {
|
||||
openLoginDialog();
|
||||
return;
|
||||
}
|
||||
@ -1166,6 +1166,11 @@ export function LovartHome({
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (response.status === 401) {
|
||||
openLoginDialog();
|
||||
throw new Error("请先登录正式账号后再充值");
|
||||
}
|
||||
|
||||
if (!response.ok || !result?.paymentUrl) {
|
||||
throw new Error(result?.error || "创建支付订单失败");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user