tierrun / tier-vercel-openai

This project generates marketing content using OpenAI, implements metered pricing model, checks for feature access based on their current subscription, reports usage of a feature, manages subscription and more using Tier.
https://tier-vercel-openai.vercel.app
MIT License
339 stars 50 forks source link

Redirect after payment is directing to localhost:8081 #13

Open SalahBioPhysics opened 1 year ago

SalahBioPhysics commented 1 year ago

Describe the bug When subscribing to the free plan the app redirect to the right place www.example.com/generate but when the user subscribe to the non-free plan the redirect send the user to localhost:8081/generate

Additional context I'm using google app engine for hosting.

jerriclynsjohn commented 1 year ago

Can you let me know if you have set the environment variable NEXT_PUBLIC_APP_URL? Setting it should solve the problem.

SalahBioPhysics commented 1 year ago

Yes I have NEXT_PUBLIC_APP_URL set inside .env. The redirect send to the right place when doing development but when in production it always redirect to http://localhost:8081/generate

SalahBioPhysics commented 1 year ago

I believe the issue comes from the following line const successUrl = new URL(/api/subscribe?plan=${plan}, env.NEXT_PUBLIC_APP_URL).toString(); in this file src/app/api/change-plan/route.ts. Is this a correct url or an API endpoint?

SalahBioPhysics commented 1 year ago

When I change this line in src/app/api/subscribe/route.ts from return NextResponse.redirect(new URL("/generate", req.url)); to return NextResponse.redirect(new URL("/generate", 'https://example.com')); it works fine. Hopefully that helps

jerriclynsjohn commented 1 year ago

I'm actually confused here, is this happening because Google app engine is not reading the envs? I mean according to you it works when it is hardcoded!

SalahBioPhysics commented 1 year ago

I'm confused as well, yes it could be the google app engine, if I ever find out why I will post it here.