diff --git a/app/(app)/unsorted/actions.ts b/app/(app)/unsorted/actions.ts index 29e8e67..30d0615 100644 --- a/app/(app)/unsorted/actions.ts +++ b/app/(app)/unsorted/actions.ts @@ -6,7 +6,7 @@ import { buildLLMPrompt } from "@/ai/prompt" import { fieldsToJsonSchema } from "@/ai/schema" import { transactionFormSchema } from "@/forms/transactions" import { ActionState } from "@/lib/actions" -import { getCurrentUser, isSubscriptionExpired } from "@/lib/auth" +import { getCurrentUser, isAiBalanceExhausted, isSubscriptionExpired } from "@/lib/auth" import config from "@/lib/config" import { getTransactionFileUploadPath, getUserUploadsDirectory } from "@/lib/files" import { DEFAULT_PROMPT_ANALYSE_NEW_FILE } from "@/models/defaults" @@ -36,19 +36,17 @@ export async function analyzeFileAction( return { success: false, error: "OpenAI API key is not set" } } - if (!config.selfHosted.isEnabled) { - if (user.aiBalance <= 0) { - return { - success: false, - error: "You used all of your pre-paid AI scans, please upgrade your account or buy new subscription plan", - } + if (isAiBalanceExhausted(user)) { + return { + success: false, + error: "You used all of your pre-paid AI scans, please upgrade your account or buy new subscription plan", } + } - if (isSubscriptionExpired(user)) { - return { - success: false, - error: "Your subscription has expired, please upgrade your account or buy new subscription plan", - } + if (isSubscriptionExpired(user)) { + return { + success: false, + error: "Your subscription has expired, please upgrade your account or buy new subscription plan", } } diff --git a/app/landing/landing.tsx b/app/landing/landing.tsx index f4f2179..95e5f14 100644 --- a/app/landing/landing.tsx +++ b/app/landing/landing.tsx @@ -323,9 +323,6 @@ export default function LandingPage() {
-
- 🚀 Under Active Development -

Upcoming Features

diff --git a/lib/auth.ts b/lib/auth.ts index 8fcb4f8..61ad109 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -1,5 +1,5 @@ import config from "@/lib/config" -import { getSelfHostedUser, getUserByEmail, getUserById } from "@/models/users" +import { getSelfHostedUser, getUserByEmail, getUserById, SELF_HOSTED_USER } from "@/models/users" import { User } from "@prisma/client" import { betterAuth } from "better-auth" import { prismaAdapter } from "better-auth/adapters/prisma" @@ -101,3 +101,10 @@ export function isSubscriptionExpired(user: User) { } return user.membershipExpiresAt && user.membershipExpiresAt < new Date() } + +export function isAiBalanceExhausted(user: User) { + if (config.selfHosted.isEnabled || user.membershipPlan === SELF_HOSTED_USER.membershipPlan) { + return false + } + return user.aiBalance <= 0 +}