How to redirect using TRPC?
I am generating stripe checkout url from trpc endpoint and want to redirect user to that page.
Here is what I am doing right now
Here is what I am doing right now
export const purchaseRouter = createTRPCRouter({
getUrl: publicProcedure
.input(z.object({ text: z.string() }))
.query(async ({ input, ctx }) => {
const host = ctx.req.headers.host;
if (!host) {
throw new Error("No host");
}
const session = await stripe.checkout.sessions.create({
line_items: [
{
price: "price_1N7vQ8CxIhQOHpG7clowFgAm",
quantity: 1,
},
],
mode: "payment",
success_url: `https://${host}/?success=true`,
cancel_url: `https://${host}/?canceled=true`,
});
ctx.res.redirect(303, session.url);
}),
});export const purchaseRouter = createTRPCRouter({
getUrl: publicProcedure
.input(z.object({ text: z.string() }))
.query(async ({ input, ctx }) => {
const host = ctx.req.headers.host;
if (!host) {
throw new Error("No host");
}
const session = await stripe.checkout.sessions.create({
line_items: [
{
price: "price_1N7vQ8CxIhQOHpG7clowFgAm",
quantity: 1,
},
],
mode: "payment",
success_url: `https://${host}/?success=true`,
cancel_url: `https://${host}/?canceled=true`,
});
ctx.res.redirect(303, session.url);
}),
});