-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Don't allow >100k emails per month
- Loading branch information
1 parent
d8cbfef
commit dcb5202
Showing
5 changed files
with
68 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,12 @@ import amqplib from "amqplib"; | |
import { supabaseAdmin } from "@/supabase/supabaseAdmin"; | ||
import { sentryException } from "@/util/sentry"; | ||
import { ENABLE_BULK, getWebappURL } from "@/util/helpers"; | ||
import { | ||
checkUserInDB, | ||
isEarlyResponse, | ||
} from "@/app/api/v0/check_email/checkUserInDb"; | ||
import { SAAS_100K_PRODUCT_ID } from "@/util/subs"; | ||
import { isEarlyResponse } from "@/app/api/v0/check_email/checkUserInDb"; | ||
import { SAAS_100K_PRODUCT_ID, getApiUsage } from "@/util/subs"; | ||
import { Json } from "@/supabase/database.types"; | ||
import { cookies } from "next/headers"; | ||
import { createClient } from "@/supabase/server"; | ||
import { getSubscription } from "@/supabase/supabaseServer"; | ||
|
||
interface BulkPayload { | ||
input_type: "array"; | ||
|
@@ -25,9 +25,24 @@ export const POST = async (req: NextRequest): Promise<Response> => { | |
} | ||
|
||
try { | ||
const { user, subAndCalls } = await checkUserInDB(req); | ||
const cookieStore = cookies(); | ||
const supabase = createClient(cookieStore); | ||
const { | ||
data: { user }, | ||
} = await supabase.auth.getUser(); | ||
if (!user) { | ||
return Response.json( | ||
{ | ||
error: "Not logged in", | ||
}, | ||
{ | ||
status: 401, | ||
} | ||
); | ||
} | ||
const subscripton = await getSubscription(); | ||
|
||
if (subAndCalls.product_id !== SAAS_100K_PRODUCT_ID) { | ||
if (subscripton?.prices?.product_id !== SAAS_100K_PRODUCT_ID) { | ||
return Response.json( | ||
{ | ||
error: "Bulk verification is not available on your plan", | ||
|
@@ -39,10 +54,13 @@ export const POST = async (req: NextRequest): Promise<Response> => { | |
} | ||
|
||
const payload: BulkPayload = await req.json(); | ||
if (payload.input.length > 100000) { | ||
|
||
const callsUsed = await getApiUsage(supabase, subscripton); | ||
|
||
if (payload.input.length + callsUsed > 100_000) { | ||
return Response.json( | ||
{ | ||
error: "Bulk verification is limited to 100_000 emails", | ||
error: "Verifying more than 100,000 emails per month is not available on your plan. Please contact [email protected] to upgrade to the Commercial License.", | ||
}, | ||
{ | ||
status: 403, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,7 @@ button { | |
.mt-0 { | ||
margin-top: 0; | ||
} | ||
|
||
.green { | ||
color: green !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dcb5202
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
webapp – ./
webapp-reacher.vercel.app
app.reacher.email
webapp-git-production-reacher.vercel.app
api.reacher.email