mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-25 22:36:38 +00:00
♻️ check for licence when checking for subscription
This commit is contained in:
@@ -30,6 +30,7 @@ import { GetOrgTierResponse } from "@server/routers/billing/types";
|
|||||||
import { TierId } from "@server/lib/billing/tiers";
|
import { TierId } from "@server/lib/billing/tiers";
|
||||||
import { getCachedSubscription } from "@app/lib/api/getCachedSubscription";
|
import { getCachedSubscription } from "@app/lib/api/getCachedSubscription";
|
||||||
import { replacePlaceholder } from "@app/lib/replacePlaceholder";
|
import { replacePlaceholder } from "@app/lib/replacePlaceholder";
|
||||||
|
import { isOrgSubscribed } from "@app/lib/api/isOrgSubscribed";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
@@ -77,17 +78,7 @@ export default async function OrgAuthPage(props: {
|
|||||||
redirect(env.app.dashboardUrl);
|
redirect(env.app.dashboardUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
let subscriptionStatus: GetOrgTierResponse | null = null;
|
const subscribed = await isOrgSubscribed(loginPage.orgId);
|
||||||
if (build === "saas") {
|
|
||||||
try {
|
|
||||||
const subRes = await getCachedSubscription(loginPage.orgId);
|
|
||||||
subscriptionStatus = subRes.data.data;
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
const subscribed =
|
|
||||||
build === "enterprise"
|
|
||||||
? true
|
|
||||||
: subscriptionStatus?.tier === TierId.STANDARD;
|
|
||||||
|
|
||||||
if (build === "saas" && !subscribed) {
|
if (build === "saas" && !subscribed) {
|
||||||
console.log(
|
console.log(
|
||||||
|
|||||||
@@ -2,20 +2,29 @@ import { build } from "@server/build";
|
|||||||
import { TierId } from "@server/lib/billing/tiers";
|
import { TierId } from "@server/lib/billing/tiers";
|
||||||
import { cache } from "react";
|
import { cache } from "react";
|
||||||
import { getCachedSubscription } from "./getCachedSubscription";
|
import { getCachedSubscription } from "./getCachedSubscription";
|
||||||
import type { GetOrgTierResponse } from "@server/routers/billing/types";
|
import { priv } from ".";
|
||||||
|
import { AxiosResponse } from "axios";
|
||||||
|
import { GetLicenseStatusResponse } from "@server/routers/license/types";
|
||||||
|
|
||||||
export const isOrgSubscribed = cache(async (orgId: string) => {
|
export const isOrgSubscribed = cache(async (orgId: string) => {
|
||||||
let subscriptionStatus: GetOrgTierResponse | null = null;
|
let subscribed = false;
|
||||||
try {
|
|
||||||
const subRes = await getCachedSubscription(orgId);
|
|
||||||
subscriptionStatus = subRes.data.data;
|
|
||||||
} catch {}
|
|
||||||
|
|
||||||
const subscribed =
|
if (build === "enterprise") {
|
||||||
build === "enterprise"
|
try {
|
||||||
? true
|
const licenseStatusRes =
|
||||||
: subscriptionStatus?.tier === TierId.STANDARD &&
|
await priv.get<AxiosResponse<GetLicenseStatusResponse>>(
|
||||||
subscriptionStatus.active;
|
"/license/status"
|
||||||
|
);
|
||||||
|
subscribed = licenseStatusRes.data.data.isLicenseValid;
|
||||||
|
} catch (error) {}
|
||||||
|
} else if (build === "saas") {
|
||||||
|
try {
|
||||||
|
const subRes = await getCachedSubscription(orgId);
|
||||||
|
subscribed =
|
||||||
|
subRes.data.data.tier === TierId.STANDARD &&
|
||||||
|
subRes.data.data.active;
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
return subscribed;
|
return subscribed;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user