Skip to content

Commit

Permalink
Refactor chatAccess object assignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
bLopata committed Dec 20, 2024
1 parent 3809082 commit a4bf4a3
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions www/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getSubscription, getChatAccess } from '@/utils/supabase/queries';
import { getChatAccess } from '@/utils/supabase/queries';
import { createClient } from '@/utils/supabase/server';
import { redirect } from 'next/navigation';
import Chat from './Chat';
Expand All @@ -21,26 +21,14 @@ export default async function Home() {
}

// Get initial subscription state
let isSubscribed = false;
let freeMessages = 0;
let chatAccess;

if (process.env.NEXT_PUBLIC_STRIPE_ENABLED === 'false') {
// In development, get the real message count but override subscription status
const realChatAccess = await getChatAccess(supabase, user.id);
chatAccess = {
isSubscribed: true,
freeMessages: realChatAccess.freeMessages,
canChat: realChatAccess.isSubscribed || realChatAccess.freeMessages > 0 // Always allow chat in development
};
isSubscribed = true;
} else {
chatAccess = await getChatAccess(supabase, user.id);
isSubscribed = chatAccess.isSubscribed;
freeMessages = chatAccess.freeMessages;
// Set canChat based on subscription status or free message availability
chatAccess.canChat = chatAccess.isSubscribed || chatAccess.freeMessages > 0;
}
const realChatAccess = await getChatAccess(supabase, user.id);
const isDevMode = process.env.NEXT_PUBLIC_STRIPE_ENABLED === 'false';

const chatAccess = {
isSubscribed: isDevMode ? true : realChatAccess.isSubscribed,
freeMessages: realChatAccess.freeMessages,
canChat: isDevMode ? true : (realChatAccess.isSubscribed || realChatAccess.freeMessages > 0)
};

// Get initial conversations
const conversations = await getConversations();
Expand Down

0 comments on commit a4bf4a3

Please sign in to comment.