From 09c4099ca5ce5e9158267b3df672a3c2daf555e9 Mon Sep 17 00:00:00 2001 From: marko-kraemer Date: Sat, 26 Apr 2025 20:54:41 +0100 Subject: [PATCH] temp wip, downgrade & upgrade w. credit not implemented --- frontend/src/app/auth/page.tsx | 5 ++++- frontend/src/lib/actions/billing.ts | 15 +++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/auth/page.tsx b/frontend/src/app/auth/page.tsx index 42277f37..75096c52 100644 --- a/frontend/src/app/auth/page.tsx +++ b/frontend/src/app/auth/page.tsx @@ -101,6 +101,8 @@ function LoginContent() { const handleSignIn = async (prevState: any, formData: FormData) => { if (returnUrl) { formData.append("returnUrl", returnUrl); + } else { + formData.append("returnUrl", "/dashboard"); } return signIn(prevState, formData); }; @@ -166,9 +168,10 @@ function LoginContent() { const resetRegistrationSuccess = () => { setRegistrationSuccess(false); - // Remove message from URL + // Remove message from URL and set mode to signin const params = new URLSearchParams(window.location.search); params.delete('message'); + params.set('mode', 'signin'); const newUrl = window.location.pathname + diff --git a/frontend/src/lib/actions/billing.ts b/frontend/src/lib/actions/billing.ts index a50e203f..43ab377d 100644 --- a/frontend/src/lib/actions/billing.ts +++ b/frontend/src/lib/actions/billing.ts @@ -84,7 +84,7 @@ export async function getAccountSubscription(accountId: string) { const supabaseClient = await createClient(); // Get account subscription data - const { data: subscriptionData, error: subscriptionError } = await supabaseClient + let { data: subscriptionData, error: subscriptionError } = await supabaseClient .schema('basejump') .from('billing_subscriptions') .select('*') @@ -94,9 +94,16 @@ export async function getAccountSubscription(accountId: string) { .order('created', { ascending: false }) .single(); - if (subscriptionError) { - console.error("Error fetching subscription data:", subscriptionError); - return { message: subscriptionError.message }; + // If no subscription found or error, return default FREE tier + if (subscriptionError || !subscriptionData) { + console.log("No active subscription found, defaulting to FREE tier"); + subscriptionData = { + plan_id: 'free', + status: 'active', + price_id: null, + customer_id: null, + subscription_id: null + }; } console.log("Subscription data:", subscriptionData);