mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-11 08:22:05 +02:00
suse tiermatrix in server component susbcribed check
This commit is contained in:
@@ -13,6 +13,8 @@ import { redirect } from "next/navigation";
|
|||||||
import OrgLoginPage from "@app/components/OrgLoginPage";
|
import OrgLoginPage from "@app/components/OrgLoginPage";
|
||||||
import { pullEnv } from "@app/lib/pullEnv";
|
import { pullEnv } from "@app/lib/pullEnv";
|
||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
|
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
||||||
|
import { isOrgSubscribed } from "@app/lib/api/isOrgSubscribed";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Organization Login"
|
title: "Organization Login"
|
||||||
@@ -68,15 +70,22 @@ export default async function OrgAuthPage(props: {
|
|||||||
variant: idp.variant
|
variant: idp.variant
|
||||||
})) as LoginFormIDP[];
|
})) as LoginFormIDP[];
|
||||||
|
|
||||||
|
const hasLoginPageBranding = await isOrgSubscribed(
|
||||||
|
orgId,
|
||||||
|
tierMatrix.loginPageBranding
|
||||||
|
);
|
||||||
|
|
||||||
let branding: LoadLoginPageBrandingResponse | null = null;
|
let branding: LoadLoginPageBrandingResponse | null = null;
|
||||||
try {
|
if (hasLoginPageBranding) {
|
||||||
const res = await priv.get<
|
try {
|
||||||
AxiosResponse<LoadLoginPageBrandingResponse>
|
const res = await priv.get<
|
||||||
>(`/login-page-branding?orgId=${orgId}`);
|
AxiosResponse<LoadLoginPageBrandingResponse>
|
||||||
if (res.status === 200) {
|
>(`/login-page-branding?orgId=${orgId}`);
|
||||||
branding = res.data.data;
|
if (res.status === 200) {
|
||||||
}
|
branding = res.data.data;
|
||||||
} catch (error) {}
|
}
|
||||||
|
} catch (error) {}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<OrgLoginPage
|
<OrgLoginPage
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { isOrgSubscribed } from "@app/lib/api/isOrgSubscribed";
|
|||||||
import { OrgSelectionForm } from "@app/components/OrgSelectionForm";
|
import { OrgSelectionForm } from "@app/components/OrgSelectionForm";
|
||||||
import OrgLoginPage from "@app/components/OrgLoginPage";
|
import OrgLoginPage from "@app/components/OrgLoginPage";
|
||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
|
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Choose Organization"
|
title: "Choose Organization"
|
||||||
@@ -83,7 +84,10 @@ export default async function OrgAuthPage(props: {
|
|||||||
redirect(env.app.dashboardUrl);
|
redirect(env.app.dashboardUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
const subscribed = await isOrgSubscribed(loginPage.orgId);
|
const subscribed = await isOrgSubscribed(
|
||||||
|
loginPage.orgId,
|
||||||
|
tierMatrix.loginPageDomain
|
||||||
|
);
|
||||||
|
|
||||||
if (build === "saas" && !subscribed) {
|
if (build === "saas" && !subscribed) {
|
||||||
console.log(
|
console.log(
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ 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";
|
import { isOrgSubscribed } from "@app/lib/api/isOrgSubscribed";
|
||||||
import { normalizePostAuthPath } from "@server/lib/normalizePostAuthPath";
|
import { normalizePostAuthPath } from "@server/lib/normalizePostAuthPath";
|
||||||
|
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
@@ -70,14 +71,25 @@ export default async function ResourceAuthPage(props: {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const subscribed = await isOrgSubscribed(authInfo.orgId);
|
const hasLoginPageDomain = await isOrgSubscribed(
|
||||||
|
authInfo.orgId,
|
||||||
|
tierMatrix.loginPageDomain
|
||||||
|
);
|
||||||
|
const hasOrgOidc = await isOrgSubscribed(
|
||||||
|
authInfo.orgId,
|
||||||
|
tierMatrix.orgOidc
|
||||||
|
);
|
||||||
|
const hasLoginPageBranding = await isOrgSubscribed(
|
||||||
|
authInfo.orgId,
|
||||||
|
tierMatrix.loginPageBranding
|
||||||
|
);
|
||||||
|
|
||||||
const allHeaders = await headers();
|
const allHeaders = await headers();
|
||||||
const host = allHeaders.get("host");
|
const host = allHeaders.get("host");
|
||||||
|
|
||||||
const expectedHost = env.app.dashboardUrl.split("//")[1];
|
const expectedHost = env.app.dashboardUrl.split("//")[1];
|
||||||
if (host !== expectedHost) {
|
if (host !== expectedHost) {
|
||||||
if (build === "saas" && !subscribed) {
|
if (build === "saas" && !hasLoginPageDomain) {
|
||||||
redirect(env.app.dashboardUrl);
|
redirect(env.app.dashboardUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +118,10 @@ export default async function ResourceAuthPage(props: {
|
|||||||
const redirectPort = new URL(searchParams.redirect).port;
|
const redirectPort = new URL(searchParams.redirect).port;
|
||||||
const serverResourceHostWithPort = `${serverResourceHost}:${redirectPort}`;
|
const serverResourceHostWithPort = `${serverResourceHost}:${redirectPort}`;
|
||||||
|
|
||||||
const wildcardMatchesRedirect = (wildcardDomain: string, host: string): boolean => {
|
const wildcardMatchesRedirect = (
|
||||||
|
wildcardDomain: string,
|
||||||
|
host: string
|
||||||
|
): boolean => {
|
||||||
if (!wildcardDomain.startsWith("*.")) return false;
|
if (!wildcardDomain.startsWith("*.")) return false;
|
||||||
const suffix = wildcardDomain.slice(1); // e.g. ".wildcard.owen.fosrl.io"
|
const suffix = wildcardDomain.slice(1); // e.g. ".wildcard.owen.fosrl.io"
|
||||||
return host.endsWith(suffix) && host.length > suffix.length;
|
return host.endsWith(suffix) && host.length > suffix.length;
|
||||||
@@ -228,7 +243,7 @@ export default async function ResourceAuthPage(props: {
|
|||||||
|
|
||||||
let loginIdps: LoginFormIDP[] = [];
|
let loginIdps: LoginFormIDP[] = [];
|
||||||
if (build === "saas" || env.app.identityProviderMode === "org") {
|
if (build === "saas" || env.app.identityProviderMode === "org") {
|
||||||
if (subscribed) {
|
if (hasOrgOidc) {
|
||||||
const idpsRes = await cache(
|
const idpsRes = await cache(
|
||||||
async () =>
|
async () =>
|
||||||
await priv.get<AxiosResponse<ListOrgIdpsResponse>>(
|
await priv.get<AxiosResponse<ListOrgIdpsResponse>>(
|
||||||
@@ -271,7 +286,7 @@ export default async function ResourceAuthPage(props: {
|
|||||||
|
|
||||||
let branding: LoadLoginPageBrandingResponse | null = null;
|
let branding: LoadLoginPageBrandingResponse | null = null;
|
||||||
try {
|
try {
|
||||||
if (subscribed) {
|
if (hasLoginPageBranding) {
|
||||||
const res = await priv.get<
|
const res = await priv.get<
|
||||||
AxiosResponse<LoadLoginPageBrandingResponse>
|
AxiosResponse<LoadLoginPageBrandingResponse>
|
||||||
>(`/login-page-branding?orgId=${authInfo.orgId}`);
|
>(`/login-page-branding?orgId=${authInfo.orgId}`);
|
||||||
|
|||||||
@@ -4,9 +4,13 @@ import { getCachedSubscription } from "./getCachedSubscription";
|
|||||||
import { priv } from ".";
|
import { priv } from ".";
|
||||||
import { AxiosResponse } from "axios";
|
import { AxiosResponse } from "axios";
|
||||||
import { GetLicenseStatusResponse } from "@server/routers/license/types";
|
import { GetLicenseStatusResponse } from "@server/routers/license/types";
|
||||||
|
import { Tier } from "@server/types/Tiers";
|
||||||
|
|
||||||
export const isOrgSubscribed = cache(async (orgId: string) => {
|
const DEFAULT_PAID_TIERS: Tier[] = ["tier1", "tier2", "tier3", "enterprise"];
|
||||||
|
|
||||||
|
export const isOrgSubscribed = cache(async (orgId: string, tiers?: Tier[]) => {
|
||||||
let subscribed = false;
|
let subscribed = false;
|
||||||
|
const allowedTiers = tiers ?? DEFAULT_PAID_TIERS;
|
||||||
|
|
||||||
if (build === "enterprise") {
|
if (build === "enterprise") {
|
||||||
try {
|
try {
|
||||||
@@ -20,7 +24,8 @@ export const isOrgSubscribed = cache(async (orgId: string) => {
|
|||||||
try {
|
try {
|
||||||
const subRes = await getCachedSubscription(orgId);
|
const subRes = await getCachedSubscription(orgId);
|
||||||
subscribed =
|
subscribed =
|
||||||
(subRes.data.data.tier == "tier1" || subRes.data.data.tier == "tier2" || subRes.data.data.tier == "tier3" || subRes.data.data.tier == "enterprise") &&
|
!!subRes.data.data.tier &&
|
||||||
|
allowedTiers.includes(subRes.data.data.tier as Tier) &&
|
||||||
subRes.data.data.active;
|
subRes.data.data.active;
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { priv } from "@app/lib/api";
|
import { priv } from "@app/lib/api";
|
||||||
import { isOrgSubscribed } from "@app/lib/api/isOrgSubscribed";
|
import { isOrgSubscribed } from "@app/lib/api/isOrgSubscribed";
|
||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
|
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
||||||
import { LoadLoginPageBrandingResponse } from "@server/routers/loginPage/types";
|
import { LoadLoginPageBrandingResponse } from "@server/routers/loginPage/types";
|
||||||
import { AxiosResponse } from "axios";
|
import { AxiosResponse } from "axios";
|
||||||
|
|
||||||
@@ -11,7 +12,10 @@ export async function loadOrgLoginPageBranding(orgId: string): Promise<{
|
|||||||
return { primaryColor: null };
|
return { primaryColor: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
const subscribed = await isOrgSubscribed(orgId);
|
const subscribed = await isOrgSubscribed(
|
||||||
|
orgId,
|
||||||
|
tierMatrix.loginPageBranding
|
||||||
|
);
|
||||||
if (!subscribed) {
|
if (!subscribed) {
|
||||||
return { primaryColor: null };
|
return { primaryColor: null };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user