check for stripe customer portal link in prod

This commit is contained in:
vincanger 2023-11-30 17:55:30 +01:00
parent 3fe74e40e2
commit b10fd409c9
2 changed files with 16 additions and 11 deletions

View File

@ -56,6 +56,13 @@ checkStripePortalLinkExists(STRIPE_CUSTOMER_PORTAL_LINK); // throws an error if
Note that there are variables set aside for your test portal link, as well as a production portal link. You will be warned in the console if you there is no link in the development environment, but the app will throw an error if there is no link in the production environment!
```sh
[Server] 🔍 Validating environment variables...
[Server!] 🚫 STRIPE_CUSTOMER_PORTAL_LINK is not defined.
[Server] 🚀 "Email and password" auth initialized
[Server] 🚀 "Google" auth initialized
```
## Install the Stripe CLI
To install the Stripe CLI with homebrew, run the following command in your terminal:

View File

@ -6,18 +6,16 @@ export enum TierIds {
//get this link at https://dashboard.stripe.com/test/settings/billing/portal
const isDev = process.env.NODE_ENV === 'development';
const customerPortalTestUrl: string | undefined = 'https://billing.stripe.com/p/login/test_8wM8x17JN7DT4zC000';
const customerPortalProdUrl: string | undefined = undefined;
const customerPortalTestUrl = 'https://billing.stripe.com/p/login/test_8wM8x17JN7DT4zC000';
const customerPortalProdUrl = undefined;
export const STRIPE_CUSTOMER_PORTAL_LINK = isDev ? customerPortalTestUrl : customerPortalProdUrl;
function checkStripePortalLinkExists(link: string | undefined) {
if (isDev && link === undefined) {
console.warn('\x1b[31m%s\x1b[0m', '🚫 STRIPE_CUSTOMER_PORTAL_LINK is not defined.');
} else if (!isDev && link === undefined) {
throw new Error('🚫 STRIPE_CUSTOMER_PORTAL_LINK is not defined');
} else {
console.log('🎉 STRIPE_CUSTOMER_PORTAL_LINK is defined');
}
}
checkStripePortalLinkExists(STRIPE_CUSTOMER_PORTAL_LINK);
function checkStripePortalLinkExists(link: string | undefined) {
if (!link) {
if (isDev) console.warn('\x1b[31m%s\x1b[0m', '🚫 STRIPE_CUSTOMER_PORTAL_LINK is not defined.');
if (!isDev) throw new Error('🚫 STRIPE_CUSTOMER_PORTAL_LINK is not defined');
}
}