DrillsThe Stripe secret key is in the browser
The Stripe secret key is in the browser
What happened
QuickBite's Pay button first failed with “You did not provide an API key.” Codex fixed it by renaming the variable to NEXT_PUBLIC_STRIPE_SECRET_KEY, and payments have worked since. This morning a friend who does security sent you one line from their terminal.
A friend who does securityThat's your live Stripe secret key, in your checkout page's JavaScript. Anyone can refund every order with it. Roll it today.
What you seeTerminal
$ curl -s https://quickbite-demo.app/_next/static/chunks/app/checkout/page-8c1f2e.js | grep -o "sk_live_[A-Za-z_]*"
sk_live_DEMO_DO_NOT_USE
The MagisterYou don't have to fix the code yourself. Read it until you can say, in plain words, why it breaks.
"use client";
import { useState } from "react";
import Stripe from "stripe";
import { placeOrder } from "./actions";
const stripe = new Stripe(process.env.NEXT_PUBLIC_STRIPE_SECRET_KEY!);
export function PayButton({ cartId, total }: { cartId: string; total: number }) {
const [busy, setBusy] = useState(false);
async function pay() {
setBusy(true);
const order = await placeOrder(cartId);
const session = await stripe.checkout.sessions.create({
mode: "payment",
line_items: [
{
price_data: { currency: "usd", unit_amount: order.totalCents, product_data: { name: `QuickBite order ${order.number}` } },
quantity: 1,
},
],
metadata: { orderId: order.id },
success_url: `${window.location.origin}/orders/${order.id}`,
cancel_url: `${window.location.origin}/checkout`,
});
window.location.assign(session.url!);
}
return (
<button className="qb-order" onClick={pay} disabled={busy}>
{busy ? "Opening checkout…" : `Pay $${total.toFixed(2)}`}
</button>
);
}
This one is for reading: the code needs a real database or server to run.
Your answer
Reviewed by AI against what a good fix needs. About 10 seconds.Sign in to get your answer reviewed
It's free. Anything you've typed here stays in this browser and is waiting when you come back.
Sign in with email