Jakov
Jakov
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Jakov on 4/19/2025 in #questions
How to store user's tier?
I use Theo's recommendation for Stripe integration. However, I have a question. I don't know how to store the tier of the user (free,plus or pro). Here's the webhook code:
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
apiVersion: "2025-03-31.basil",
});

const allowedEvents: Stripe.Event.Type[] = [
"checkout.session.completed",
.........
"payment_intent.canceled",
];

async function processEvent(event: Stripe.Event) {
// Skip processing if the event isn't one I'm tracking (list of all events below)
if (!allowedEvents.includes(event.type)) return;
console.log("[STRIPE WEBHOOKS] Processing event", event.type);
// All the events I track have a customerId
const { customer: customerId } = event?.data?.object as {
customer: string; // Sadly TypeScript does not know this
};
// This helps make it typesafe and also lets me know if my assumption is wrong
if (typeof customerId !== "string") {
throw new Error(
`[STRIPE HOOK][CANCER] ID isn't string.\nEvent type: ${event.type}`,
);
}

return await syncStripeDataToKV(customerId);
}

export async function POST(req: NextRequest) {
const body = await req.text();
const signature = (await headers()).get("Stripe-Signature");

if (!signature) return NextResponse.json({}, { status: 400 });

........

return NextResponse.json({ received: true });
}
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
apiVersion: "2025-03-31.basil",
});

const allowedEvents: Stripe.Event.Type[] = [
"checkout.session.completed",
.........
"payment_intent.canceled",
];

async function processEvent(event: Stripe.Event) {
// Skip processing if the event isn't one I'm tracking (list of all events below)
if (!allowedEvents.includes(event.type)) return;
console.log("[STRIPE WEBHOOKS] Processing event", event.type);
// All the events I track have a customerId
const { customer: customerId } = event?.data?.object as {
customer: string; // Sadly TypeScript does not know this
};
// This helps make it typesafe and also lets me know if my assumption is wrong
if (typeof customerId !== "string") {
throw new Error(
`[STRIPE HOOK][CANCER] ID isn't string.\nEvent type: ${event.type}`,
);
}

return await syncStripeDataToKV(customerId);
}

export async function POST(req: NextRequest) {
const body = await req.text();
const signature = (await headers()).get("Stripe-Signature");

if (!signature) return NextResponse.json({}, { status: 400 });

........

return NextResponse.json({ received: true });
}
I was thinking of storing the tier in my db, but I don't know where in this code I can get: - the tier that user subscribed to - user's id: I only have customer id, but I stored a relation of user's id and customer id in the way where I can only get customer's id by user's id (not reverse)
2 replies
TTCTheo's Typesafe Cult
Created by Jakov on 4/19/2025 in #questions
How to define `waitUntil`?
I saw function waitUntil in Theo's Stripe recommendation. How should I define that function?
5 replies
TTCTheo's Typesafe Cult
Created by Jakov on 3/22/2025 in #questions
Buying domain
Hey fellow web devs! 👋
I'm about to buy my first domain from Namecheap and had a couple of beginner questions:
1️⃣ How easy is it to connect a Namecheap domain to Vercel and Render?
2️⃣ Can I set up a custom email with my domain for free, without paying for Namecheap’s email hosting?
I know these might be basic questions, but I’d really appreciate any insights! Thanks in advance. 😊
5 replies
CDCloudflare Developers
Created by Jakov on 10/22/2024 in #pages-help
Cloudflare ignores NODE_VERSION
No description
27 replies