Created
January 13, 2023 04:58
-
-
Save dipeshhkc/7baa097d19c915490a86c71ccd32cf7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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