Skip to content

Commit 9c9d933

Browse files
fix: Stripe key not found & try fix back button
1 parent 28c1155 commit 9c9d933

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ NEXT_PUBLIC_STRIPE_PRICE_ADS_FREE=price_...
1414
NEXT_PUBLIC_STRIPE_PRICE_BYOK=price_...
1515
NEXT_PUBLIC_STRIPE_PRICE_DITECTREV=price_...
1616
NEXT_PUBLIC_STRIPE_PRICE_LOCAL=price_...
17-
NEXT_PUBLIC_STRIPE_SECRET_KEY=
17+
STRIPE_SECRET_KEY=
1818

1919
# AI Provider Keys (for Ditectrev premium service)
2020
DITECTREV_OPENAI_KEY=sk-...

.github/workflows/azure-static-web-apps-kind-plant-0e80e5803.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
# Stripe Configuration
3333
# Note: Using NEXT_PUBLIC_ prefix is required for Azure Static Web Apps runtime access
3434
# This is safe because it's only used in server-side API routes, never in client components
35-
NEXT_PUBLIC_STRIPE_SECRET_KEY: ${{ secrets.NEXT_PUBLIC_STRIPE_SECRET_KEY }}
35+
NEXT_PUBLIC_STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }}
3636
# Stripe Price IDs (environment variables, distinguished per environment)
3737
NEXT_PUBLIC_STRIPE_PRICE_ADS_FREE: ${{ vars.NEXT_PUBLIC_STRIPE_PRICE_ADS_FREE }}
3838
NEXT_PUBLIC_STRIPE_PRICE_LOCAL: ${{ vars.NEXT_PUBLIC_STRIPE_PRICE_LOCAL }}

app/api/stripe/create-checkout-session/route.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,33 @@ export async function POST(request: NextRequest) {
4444
apiVersion: "2025-11-17.clover",
4545
});
4646

47-
// Get the base URL for redirects (always use dynamic URL for Azure Static Web Apps)
48-
const baseUrl = `${request.nextUrl.protocol}//${request.nextUrl.host}`;
47+
// Get the base URL for redirects
48+
// Azure Static Web Apps may use internal hostnames, so we need to check headers
49+
const forwardedHost = request.headers.get("x-forwarded-host");
50+
const forwardedProto = request.headers.get("x-forwarded-proto") || "https";
51+
const referer = request.headers.get("referer");
52+
53+
let baseUrl: string;
54+
55+
if (forwardedHost) {
56+
// Use forwarded host from Azure Static Web Apps
57+
baseUrl = `${forwardedProto}://${forwardedHost}`;
58+
} else if (referer) {
59+
// Fallback to referer URL
60+
try {
61+
const refererUrl = new URL(referer);
62+
baseUrl = `${refererUrl.protocol}//${refererUrl.host}`;
63+
} catch {
64+
// If referer parsing fails, use the request URL
65+
baseUrl = `${request.nextUrl.protocol}//${request.nextUrl.host}`;
66+
}
67+
} else {
68+
// Last resort: use request URL (may be internal hostname)
69+
baseUrl = `${request.nextUrl.protocol}//${request.nextUrl.host}`;
70+
}
71+
72+
// Log for debugging
73+
console.log("Base URL for Stripe redirects:", baseUrl);
4974

5075
// Create Stripe checkout session
5176
const session = await stripe.checkout.sessions.create({

0 commit comments

Comments
 (0)