properly handle invite redeem with no valid subscription case

This commit is contained in:
msukkari 2025-02-13 15:21:31 -08:00
parent 0f43c00aa1
commit cf97955b23
2 changed files with 8 additions and 3 deletions

View file

@ -318,7 +318,7 @@ export const createInvite = async (email: string, userId: string, domain: string
export const redeemInvite = async (invite: Invite, userId: string): Promise<{ success: boolean } | ServiceError> =>
withAuth(async () => {
try {
await prisma.$transaction(async (tx) => {
const res = await prisma.$transaction(async (tx) => {
const org = await tx.org.findUnique({
where: {
id: invite.orgId,
@ -332,6 +332,7 @@ export const redeemInvite = async (invite: Invite, userId: string): Promise<{ su
// Incrememnt the seat count
if (org.stripeCustomerId) {
const subscription = await fetchSubscription(org.domain);
console.log("subscription", subscription)
if (isServiceError(subscription)) {
return orgInvalidSubscription();
}
@ -363,6 +364,10 @@ export const redeemInvite = async (invite: Invite, userId: string): Promise<{ su
});
});
if (isServiceError(res)) {
return res;
}
return {
success: true,
}
@ -422,7 +427,7 @@ export const setupInitialStripeCustomer = async (name: string, domain: string) =
const origin = (await headers()).get('origin')
@nocheckin
// @nocheckin
const test_clock = await stripe.testHelpers.testClocks.create({
frozen_time: Math.floor(Date.now() / 1000)
})

View file

@ -26,7 +26,7 @@ export function AcceptInviteButton({ invite, userId }: AcceptInviteButtonProps)
console.log("Failed to redeem invite: ", res)
toast({
title: "Error",
description: "Failed to redeem invite. Please try again.",
description: "Failed to redeem invite. Please ensure the organization has an active subscription.",
variant: "destructive",
})
} else {