Skip to content

Instantly share code, notes, and snippets.

@dipeshhkc
Created January 13, 2023 04:58
Show Gist options
  • Save dipeshhkc/7baa097d19c915490a86c71ccd32cf7a to your computer and use it in GitHub Desktop.
Save dipeshhkc/7baa097d19c915490a86c71ccd32cf7a to your computer and use it in GitHub Desktop.
import type { ActionFunction } from '@remix-run/server-runtime';
import { redirect } from '@remix-run/server-runtime';
import { stripe } from '~/stripe.server';
import { getLoggedInUser } from '~/user.server';
export const action: ActionFunction = async () => {
const user = await getLoggedInUser();
if (!user) {
return redirect('/');
}
const session = await stripe.billingPortal.sessions.create({
customer: user.subscription?.stripe_customer_id!,
return_url: `${process.env.ORIGIN}/dashboard`,
});
return redirect(session.url);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment