Skip to content

Commit

Permalink
fix: Upgrade prompt for less than 5 mins
Browse files Browse the repository at this point in the history
  • Loading branch information
richiemcilroy committed Jan 17, 2025
1 parent aa2e112 commit 8ceb5bd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
19 changes: 13 additions & 6 deletions apps/desktop/src/routes/editor/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -592,17 +592,24 @@ function ShareButton(props: ShareButtonProps) {
}

const metadata = await commands.getVideoMetadata(videoId, null);
const isUpgraded = await commands.checkUpgradedAndUpdate();

if (!isUpgraded) {
await commands.showWindow("Upgrade");
throw new Error("Upgrade required to share recordings");
const plan = await commands.checkUpgradedAndUpdate();
const canShare = {
allowed: plan || metadata.duration < 300,
reason: !plan && metadata.duration >= 300 ? "upgrade_required" : null,
};

if (!canShare.allowed) {
if (canShare.reason === "upgrade_required") {
await commands.showWindow("Upgrade");
throw new Error(
"Upgrade required to share recordings longer than 5 minutes"
);
}
}

let unlisten: (() => void) | undefined;

try {
// Set initial progress state
setProgressState({
type: "uploading",
renderProgress: 0,
Expand Down
5 changes: 3 additions & 2 deletions apps/desktop/src/routes/recordings-overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -992,9 +992,10 @@ function createRecordingMutations(

if (!canShare.allowed) {
if (canShare.reason === "upgrade_required") {
onEvent("upgradeRequired");
await commands.showWindow("Upgrade");
return;
throw new Error(
"Upgrade required to share recordings longer than 5 minutes"
);
}
}

Expand Down
16 changes: 16 additions & 0 deletions apps/web/app/api/desktop/subscribe/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export async function OPTIONS(req: NextRequest) {
const origin = params.get("origin") || null;
const originalOrigin = req.nextUrl.origin;

console.log("[OPTIONS] Handling OPTIONS request");

return new Response(null, {
status: 200,
headers: {
Expand All @@ -37,8 +39,11 @@ export async function OPTIONS(req: NextRequest) {
}

export async function POST(request: NextRequest) {
console.log("[POST] Starting subscription request");

const token = request.headers.get("authorization")?.split(" ")[1];
if (token) {
console.log("[POST] Setting auth cookie");
cookies().set({
name: "next-auth.session-token",
value: token,
Expand All @@ -56,7 +61,11 @@ export async function POST(request: NextRequest) {
const origin = params.get("origin") || null;
const originalOrigin = request.nextUrl.origin;

console.log("[POST] User:", user?.id);
console.log("[POST] Price ID:", priceId);

if (!priceId) {
console.log("[POST] Error: No price ID provided");
return Response.json(
{ error: true },
{
Expand All @@ -75,6 +84,7 @@ export async function POST(request: NextRequest) {
}

if (!user) {
console.log("[POST] Error: No authenticated user");
return Response.json(
{ error: true, auth: false },
{
Expand All @@ -97,6 +107,7 @@ export async function POST(request: NextRequest) {
subscriptionStatus: user.stripeSubscriptionStatus as string,
})
) {
console.log("[POST] Error: User already on Pro plan");
return Response.json(
{ error: true, subscription: true },
{
Expand All @@ -115,6 +126,7 @@ export async function POST(request: NextRequest) {
}

if (!user.stripeCustomerId) {
console.log("[POST] Creating new Stripe customer");
const customer = await stripe.customers.create({
email: user.email,
metadata: {
Expand All @@ -130,8 +142,10 @@ export async function POST(request: NextRequest) {
.where(eq(users.id, user.id));

customerId = customer.id;
console.log("[POST] Created Stripe customer:", customerId);
}

console.log("[POST] Creating checkout session");
const checkoutSession = await stripe.checkout.sessions.create({
customer: customerId as string,
line_items: [
Expand All @@ -147,6 +161,7 @@ export async function POST(request: NextRequest) {
});

if (checkoutSession.url) {
console.log("[POST] Checkout session created successfully");
return Response.json(
{ url: checkoutSession.url },
{
Expand All @@ -164,6 +179,7 @@ export async function POST(request: NextRequest) {
);
}

console.log("[POST] Error: Failed to create checkout session");
return Response.json(
{ error: true },
{
Expand Down

1 comment on commit 8ceb5bd

@vercel
Copy link

@vercel vercel bot commented on 8ceb5bd Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.