Skip to content

Commit 5814dfa

Browse files
committed
fix: subscription status for chat
1 parent 33ea3ee commit 5814dfa

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

apps/snow-leopard/app/api/user/subscription-status/route.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ export async function GET() {
88
try {
99
const session = await getSession();
1010

11-
if (!session?.user?.id) {
12-
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
13-
}
14-
15-
let hasActiveSubscription = true; // Assume true by default or if Stripe disabled
11+
// Default to allowing access. If Stripe is enabled and the requester is authenticated, evaluate their subscription.
12+
let hasActiveSubscription = true;
1613

17-
if (process.env.STRIPE_ENABLED === 'true') {
14+
if (process.env.STRIPE_ENABLED === 'true' && session?.user?.id) {
1815
const subscription = await getActiveSubscriptionByUserId({ userId: session.user.id });
16+
1917
if (subscription) {
2018
if (subscription.status === 'active') {
2119
hasActiveSubscription = true;
@@ -31,10 +29,13 @@ export async function GET() {
3129
} else {
3230
hasActiveSubscription = false;
3331
}
32+
3433
console.log(`[api/user/subscription-status] User: ${session.user.id}, Sub Status: ${subscription?.status}, HasActive: ${hasActiveSubscription}`);
34+
} else if (process.env.STRIPE_ENABLED === 'true') {
35+
// Stripe is enabled but there's no authenticated user; default to granting access.
36+
console.log('[api/user/subscription-status] No authenticated user detected. Granting access by default.');
3537
} else {
36-
console.log(`[api/user/subscription-status] Stripe DISABLED, granting access.`);
37-
hasActiveSubscription = true;
38+
console.log('[api/user/subscription-status] Stripe DISABLED, granting access.');
3839
}
3940

4041
return NextResponse.json({ hasActiveSubscription });

apps/snow-leopard/components/chat/chat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Attachment, Message, ChatRequestOptions } from 'ai';
44
import { useChat } from '@ai-sdk/react';
55
import { useState, useEffect } from 'react';
66
import { ChatHeader } from '@/components/chat/chat-header';
7-
import { fetcher, generateUUID } from '@/lib/utils';
7+
import { generateUUID } from '@/lib/utils';
88
import { MultimodalInput } from './multimodal-input';
99
import { Messages } from './messages';
1010
import { toast } from 'sonner';

apps/snow-leopard/lib/ai/tools/create-document.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const createDocument = ({ session, dataStream }: CreateDocumentProps) =>
4040
// Stream the new ID to the client
4141
dataStream.writeData({ type: 'id', content: newDocumentId });
4242
// Delay to allow page navigation and editor initialization
43-
await new Promise((resolve) => setTimeout(resolve, 4000));
43+
await new Promise((resolve) => setTimeout(resolve, 4500));
4444
// Signal that creation is finished
4545
dataStream.writeData({ type: 'finish', content: '' });
4646

0 commit comments

Comments
 (0)