#you should never use ur domain at server
1 messages · Page 1 of 1 (latest)
Well I have a route.ts for creating a portal for stripe subscription :
import { NextResponse } from 'next/server';
import { stripe } from '@/lib/stripe/stripe';
import { getURL } from '@/lib/stripe/stripe-helpers';
import { createOrRetrieveCustomer } from '@/lib/supabase/supabase-admin';
import { createRouteHandlerClient } from '@/lib/supabase/route';
export async function POST() {
try {
const supabase = createRouteHandlerClient();
const {
data: { user },
} = await supabase.auth.getUser();
if (!user) throw Error('Could not get user');
const customer = await createOrRetrieveCustomer({
uuid: user.id || '',
email: user.email || '',
});
if (!customer) throw Error('Could not get customer');
const { url } = await stripe.billingPortal.sessions.create({
customer,
return_url: `${getURL()}/settings/subscription`, // <==================== HERE
});
return NextResponse.json({ url });
} catch (err: any) {
console.log(err);
new NextResponse('Internal Error', { status: 500 });
}
}
U can see the getURL() function just to be able to retrieve the url when leaving billing portal from stripe
The billingPortal from Stripe need a return url so I dont have the choice to put my domaine
i think that should be done at client side
What is the problem with server side ? Sry for dumb question :/
but yeah I can use client side for this
use client side by using at server side ur making ur own problems
will consume more server power