Skip to content

Commit 8f9be16

Browse files
committed
feat(whitelabeling): implement public whitelabeling configuration retrieval
- Added a new service to fetch public whitelabeling configuration for unauthenticated contexts. - Updated the whitelabeling router to utilize the new service for public requests. - Enhanced license validation checks to ensure proper access control based on organization licenses.
1 parent 86f941d commit 8f9be16

3 files changed

Lines changed: 66 additions & 22 deletions

File tree

‎apps/dokploy/server/api/routers/proprietary/whitelabeling.ts‎

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {
2+
getPublicWhitelabelingConfig,
23
getWebServerSettings,
4+
hasValidLicense,
35
IS_CLOUD,
46
updateWebServerSettings,
57
} from "@dokploy/server";
@@ -13,10 +15,13 @@ import {
1315
} from "../../trpc";
1416

1517
export const whitelabelingRouter = createTRPCRouter({
16-
get: protectedProcedure.query(async () => {
18+
get: protectedProcedure.query(async ({ ctx }) => {
1719
if (IS_CLOUD) {
1820
return null;
1921
}
22+
if (!(await hasValidLicense(ctx.session.activeOrganizationId))) {
23+
return null;
24+
}
2025
const settings = await getWebServerSettings();
2126
return settings?.whitelabelingConfig ?? null;
2227
}),
@@ -82,25 +87,5 @@ export const whitelabelingRouter = createTRPCRouter({
8287

8388
// Public endpoint only for unauthenticated pages (login, register, error)
8489
// Returns only the fields needed for public pages
85-
getPublic: publicProcedure.query(async () => {
86-
if (IS_CLOUD) {
87-
return null;
88-
}
89-
const settings = await getWebServerSettings();
90-
const config = settings?.whitelabelingConfig;
91-
if (!config) return null;
92-
93-
return {
94-
appName: config.appName,
95-
appDescription: config.appDescription,
96-
logoUrl: config.logoUrl,
97-
loginLogoUrl: config.loginLogoUrl,
98-
faviconUrl: config.faviconUrl,
99-
customCss: config.customCss,
100-
metaTitle: config.metaTitle,
101-
errorPageTitle: config.errorPageTitle,
102-
errorPageDescription: config.errorPageDescription,
103-
footerText: config.footerText,
104-
};
105-
}),
90+
getPublic: publicProcedure.query(() => getPublicWhitelabelingConfig()),
10691
});

‎packages/server/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export * from "./services/project";
3838
export * from "./services/proprietary/forward-auth";
3939
export * from "./services/proprietary/license-key";
4040
export * from "./services/proprietary/sso";
41+
export * from "./services/proprietary/whitelabeling";
4142
export * from "./services/redirect";
4243
export * from "./services/redis";
4344
export * from "./services/registry";
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { IS_CLOUD } from "@dokploy/server/constants";
2+
import { db } from "@dokploy/server/db";
3+
import { hasValidLicense } from "@dokploy/server/services/proprietary/license-key";
4+
import { getWebServerSettings } from "@dokploy/server/services/web-server-settings";
5+
6+
export interface PublicWhitelabelingConfig {
7+
appName: string | null;
8+
appDescription: string | null;
9+
logoUrl: string | null;
10+
loginLogoUrl: string | null;
11+
faviconUrl: string | null;
12+
customCss: string | null;
13+
metaTitle: string | null;
14+
errorPageTitle: string | null;
15+
errorPageDescription: string | null;
16+
footerText: string | null;
17+
}
18+
19+
// Self-hosted is single-tenant; gate on the oldest organization's license,
20+
// mirroring resolveLocalConcurrency in server/queues/concurrency.ts. Used only
21+
// for unauthenticated requests (no active organization in session).
22+
const hasAnyValidLicense = async (): Promise<boolean> => {
23+
const org = await db.query.organization.findFirst({
24+
columns: { id: true },
25+
orderBy: (organization, { asc }) => [asc(organization.createdAt)],
26+
});
27+
return org ? await hasValidLicense(org.id) : false;
28+
};
29+
30+
/**
31+
* Public whitelabeling config for unauthenticated contexts (login page, SSR
32+
* document shell). No active organization/session is available here.
33+
*/
34+
export const getPublicWhitelabelingConfig =
35+
async (): Promise<PublicWhitelabelingConfig | null> => {
36+
if (IS_CLOUD) {
37+
return null;
38+
}
39+
if (!(await hasAnyValidLicense())) {
40+
return null;
41+
}
42+
const settings = await getWebServerSettings();
43+
const config = settings?.whitelabelingConfig;
44+
if (!config) return null;
45+
46+
return {
47+
appName: config.appName,
48+
appDescription: config.appDescription,
49+
logoUrl: config.logoUrl,
50+
loginLogoUrl: config.loginLogoUrl,
51+
faviconUrl: config.faviconUrl,
52+
customCss: config.customCss,
53+
metaTitle: config.metaTitle,
54+
errorPageTitle: config.errorPageTitle,
55+
errorPageDescription: config.errorPageDescription,
56+
footerText: config.footerText,
57+
};
58+
};

0 commit comments

Comments
 (0)