♻️ load branding only if correctly subscribed

This commit is contained in:
Fred KISSIE
2025-11-18 03:14:20 +01:00
parent e00c3f2193
commit e867de023a
2 changed files with 13 additions and 24 deletions

View File

@@ -27,6 +27,7 @@ import { GetOrgTierResponse } from "@server/routers/billing/types";
import { TierId } from "@server/lib/billing/tiers"; import { TierId } from "@server/lib/billing/tiers";
import { CheckOrgUserAccessResponse } from "@server/routers/org"; import { CheckOrgUserAccessResponse } from "@server/routers/org";
import OrgPolicyRequired from "@app/components/OrgPolicyRequired"; import OrgPolicyRequired from "@app/components/OrgPolicyRequired";
import { isOrgSubscribed } from "@app/lib/api/isOrgSubscribed";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
@@ -65,22 +66,7 @@ export default async function ResourceAuthPage(props: {
); );
} }
let subscriptionStatus: GetOrgTierResponse | null = null; const subscribed = await isOrgSubscribed(authInfo.orgId);
if (build === "saas") {
try {
const getSubscription = cache(() =>
priv.get<AxiosResponse<GetOrgTierResponse>>(
`/org/${authInfo.orgId}/billing/tier`
)
);
const subRes = await getSubscription();
subscriptionStatus = subRes.data.data;
} catch {}
}
const subscribed =
build === "enterprise"
? true
: subscriptionStatus?.tier === TierId.STANDARD;
const allHeaders = await headers(); const allHeaders = await headers();
const host = allHeaders.get("host"); const host = allHeaders.get("host");
@@ -254,7 +240,7 @@ export default async function ResourceAuthPage(props: {
resourceId={authInfo.resourceId} resourceId={authInfo.resourceId}
skipToIdpId={authInfo.skipToIdpId} skipToIdpId={authInfo.skipToIdpId}
redirectUrl={redirectUrl} redirectUrl={redirectUrl}
orgId={build == "saas" ? authInfo.orgId : undefined} orgId={build === "saas" ? authInfo.orgId : undefined}
/> />
); );
} }
@@ -262,11 +248,13 @@ export default async function ResourceAuthPage(props: {
let branding: LoadLoginPageBrandingResponse | null = null; let branding: LoadLoginPageBrandingResponse | null = null;
try { try {
const res = await priv.get< if (subscribed) {
AxiosResponse<LoadLoginPageBrandingResponse> const res = await priv.get<
>(`/login-page-branding?orgId=${authInfo.orgId}`); AxiosResponse<LoadLoginPageBrandingResponse>
if (res.status === 200) { >(`/login-page-branding?orgId=${authInfo.orgId}`);
branding = res.data.data; if (res.status === 200) {
branding = res.data.data;
}
} }
} catch (error) {} } catch (error) {}

View File

@@ -4,7 +4,7 @@ import { cache } from "react";
import { getCachedSubscription } from "./getCachedSubscription"; import { getCachedSubscription } from "./getCachedSubscription";
import type { GetOrgTierResponse } from "@server/routers/billing/types"; import type { GetOrgTierResponse } from "@server/routers/billing/types";
export const isSubscribed = cache(async (orgId: string) => { export const isOrgSubscribed = cache(async (orgId: string) => {
let subscriptionStatus: GetOrgTierResponse | null = null; let subscriptionStatus: GetOrgTierResponse | null = null;
try { try {
const subRes = await getCachedSubscription(orgId); const subRes = await getCachedSubscription(orgId);
@@ -14,7 +14,8 @@ export const isSubscribed = cache(async (orgId: string) => {
const subscribed = const subscribed =
build === "enterprise" build === "enterprise"
? true ? true
: subscriptionStatus?.tier === TierId.STANDARD; : subscriptionStatus?.tier === TierId.STANDARD &&
subscriptionStatus.active;
return subscribed; return subscribed;
}); });