mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-15 05:45:20 +00:00
properly handle invite redeem with no valid subscription case
This commit is contained in:
parent
0f43c00aa1
commit
cf97955b23
2 changed files with 8 additions and 3 deletions
|
|
@ -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> =>
|
export const redeemInvite = async (invite: Invite, userId: string): Promise<{ success: boolean } | ServiceError> =>
|
||||||
withAuth(async () => {
|
withAuth(async () => {
|
||||||
try {
|
try {
|
||||||
await prisma.$transaction(async (tx) => {
|
const res = await prisma.$transaction(async (tx) => {
|
||||||
const org = await tx.org.findUnique({
|
const org = await tx.org.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: invite.orgId,
|
id: invite.orgId,
|
||||||
|
|
@ -332,6 +332,7 @@ export const redeemInvite = async (invite: Invite, userId: string): Promise<{ su
|
||||||
// Incrememnt the seat count
|
// Incrememnt the seat count
|
||||||
if (org.stripeCustomerId) {
|
if (org.stripeCustomerId) {
|
||||||
const subscription = await fetchSubscription(org.domain);
|
const subscription = await fetchSubscription(org.domain);
|
||||||
|
console.log("subscription", subscription)
|
||||||
if (isServiceError(subscription)) {
|
if (isServiceError(subscription)) {
|
||||||
return orgInvalidSubscription();
|
return orgInvalidSubscription();
|
||||||
}
|
}
|
||||||
|
|
@ -363,6 +364,10 @@ export const redeemInvite = async (invite: Invite, userId: string): Promise<{ su
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isServiceError(res)) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
}
|
}
|
||||||
|
|
@ -422,7 +427,7 @@ export const setupInitialStripeCustomer = async (name: string, domain: string) =
|
||||||
|
|
||||||
const origin = (await headers()).get('origin')
|
const origin = (await headers()).get('origin')
|
||||||
|
|
||||||
@nocheckin
|
// @nocheckin
|
||||||
const test_clock = await stripe.testHelpers.testClocks.create({
|
const test_clock = await stripe.testHelpers.testClocks.create({
|
||||||
frozen_time: Math.floor(Date.now() / 1000)
|
frozen_time: Math.floor(Date.now() / 1000)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ export function AcceptInviteButton({ invite, userId }: AcceptInviteButtonProps)
|
||||||
console.log("Failed to redeem invite: ", res)
|
console.log("Failed to redeem invite: ", res)
|
||||||
toast({
|
toast({
|
||||||
title: "Error",
|
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",
|
variant: "destructive",
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue