mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-18 18:05:18 +00:00
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.
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
|
getPublicWhitelabelingConfig,
|
||||||
getWebServerSettings,
|
getWebServerSettings,
|
||||||
|
hasValidLicense,
|
||||||
IS_CLOUD,
|
IS_CLOUD,
|
||||||
updateWebServerSettings,
|
updateWebServerSettings,
|
||||||
} from "@dokploy/server";
|
} from "@dokploy/server";
|
||||||
@@ -13,10 +15,13 @@ import {
|
|||||||
} from "../../trpc";
|
} from "../../trpc";
|
||||||
|
|
||||||
export const whitelabelingRouter = createTRPCRouter({
|
export const whitelabelingRouter = createTRPCRouter({
|
||||||
get: protectedProcedure.query(async () => {
|
get: protectedProcedure.query(async ({ ctx }) => {
|
||||||
if (IS_CLOUD) {
|
if (IS_CLOUD) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (!(await hasValidLicense(ctx.session.activeOrganizationId))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const settings = await getWebServerSettings();
|
const settings = await getWebServerSettings();
|
||||||
return settings?.whitelabelingConfig ?? null;
|
return settings?.whitelabelingConfig ?? null;
|
||||||
}),
|
}),
|
||||||
@@ -82,25 +87,5 @@ export const whitelabelingRouter = createTRPCRouter({
|
|||||||
|
|
||||||
// Public endpoint only for unauthenticated pages (login, register, error)
|
// Public endpoint only for unauthenticated pages (login, register, error)
|
||||||
// Returns only the fields needed for public pages
|
// Returns only the fields needed for public pages
|
||||||
getPublic: publicProcedure.query(async () => {
|
getPublic: publicProcedure.query(() => getPublicWhitelabelingConfig()),
|
||||||
if (IS_CLOUD) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const settings = await getWebServerSettings();
|
|
||||||
const config = settings?.whitelabelingConfig;
|
|
||||||
if (!config) return null;
|
|
||||||
|
|
||||||
return {
|
|
||||||
appName: config.appName,
|
|
||||||
appDescription: config.appDescription,
|
|
||||||
logoUrl: config.logoUrl,
|
|
||||||
loginLogoUrl: config.loginLogoUrl,
|
|
||||||
faviconUrl: config.faviconUrl,
|
|
||||||
customCss: config.customCss,
|
|
||||||
metaTitle: config.metaTitle,
|
|
||||||
errorPageTitle: config.errorPageTitle,
|
|
||||||
errorPageDescription: config.errorPageDescription,
|
|
||||||
footerText: config.footerText,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ export * from "./services/project";
|
|||||||
export * from "./services/proprietary/forward-auth";
|
export * from "./services/proprietary/forward-auth";
|
||||||
export * from "./services/proprietary/license-key";
|
export * from "./services/proprietary/license-key";
|
||||||
export * from "./services/proprietary/sso";
|
export * from "./services/proprietary/sso";
|
||||||
|
export * from "./services/proprietary/whitelabeling";
|
||||||
export * from "./services/redirect";
|
export * from "./services/redirect";
|
||||||
export * from "./services/redis";
|
export * from "./services/redis";
|
||||||
export * from "./services/registry";
|
export * from "./services/registry";
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import { IS_CLOUD } from "@dokploy/server/constants";
|
||||||
|
import { db } from "@dokploy/server/db";
|
||||||
|
import { hasValidLicense } from "@dokploy/server/services/proprietary/license-key";
|
||||||
|
import { getWebServerSettings } from "@dokploy/server/services/web-server-settings";
|
||||||
|
|
||||||
|
export interface PublicWhitelabelingConfig {
|
||||||
|
appName: string | null;
|
||||||
|
appDescription: string | null;
|
||||||
|
logoUrl: string | null;
|
||||||
|
loginLogoUrl: string | null;
|
||||||
|
faviconUrl: string | null;
|
||||||
|
customCss: string | null;
|
||||||
|
metaTitle: string | null;
|
||||||
|
errorPageTitle: string | null;
|
||||||
|
errorPageDescription: string | null;
|
||||||
|
footerText: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Self-hosted is single-tenant; gate on the oldest organization's license,
|
||||||
|
// mirroring resolveLocalConcurrency in server/queues/concurrency.ts. Used only
|
||||||
|
// for unauthenticated requests (no active organization in session).
|
||||||
|
const hasAnyValidLicense = async (): Promise<boolean> => {
|
||||||
|
const org = await db.query.organization.findFirst({
|
||||||
|
columns: { id: true },
|
||||||
|
orderBy: (organization, { asc }) => [asc(organization.createdAt)],
|
||||||
|
});
|
||||||
|
return org ? await hasValidLicense(org.id) : false;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public whitelabeling config for unauthenticated contexts (login page, SSR
|
||||||
|
* document shell). No active organization/session is available here.
|
||||||
|
*/
|
||||||
|
export const getPublicWhitelabelingConfig =
|
||||||
|
async (): Promise<PublicWhitelabelingConfig | null> => {
|
||||||
|
if (IS_CLOUD) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!(await hasAnyValidLicense())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const settings = await getWebServerSettings();
|
||||||
|
const config = settings?.whitelabelingConfig;
|
||||||
|
if (!config) return null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
appName: config.appName,
|
||||||
|
appDescription: config.appDescription,
|
||||||
|
logoUrl: config.logoUrl,
|
||||||
|
loginLogoUrl: config.loginLogoUrl,
|
||||||
|
faviconUrl: config.faviconUrl,
|
||||||
|
customCss: config.customCss,
|
||||||
|
metaTitle: config.metaTitle,
|
||||||
|
errorPageTitle: config.errorPageTitle,
|
||||||
|
errorPageDescription: config.errorPageDescription,
|
||||||
|
footerText: config.footerText,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user