Skip to content

Commit

Permalink
filter instead of throwing for valid purchases (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelhooks authored Sep 25, 2024
1 parent 95d9a86 commit d678c3a
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions app/utils/epic.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,16 @@ export async function validateUserPurchase({
)
}

const noAccessStatuses = ['Refunded', 'Disputed', 'Banned']
const validPurchaseStatuses = ['Valid', 'Restricted']

if (
userInfoResult.data.purchases.some(p => noAccessStatuses.includes(p.status))
) {
throw json(
{ status: 'error', error: 'User has a refunded purchase' } as const,
{ status: 400 },
)
}
const validPurchases = userInfoResult.data.purchases.filter((p) =>
validPurchaseStatuses.includes(p.status)
)

const hasEpicWebPurchase = userInfoResult.data.purchases.some(p =>
const hasEpicWebPurchase = validPurchases.some(p =>
epicWebProductIds.includes(p.productId),
)
const hasEpicReactPurchase = userInfoResult.data.purchases.some(p =>
const hasEpicReactPurchase = validPurchases.some(p =>
epicReactProductIds.includes(p.productId),
)

Expand Down

0 comments on commit d678c3a

Please sign in to comment.