management labelpolicy

This commit is contained in:
Max Peintner
2023-04-21 13:49:15 +02:00
parent 238a73d923
commit 12eb60c084
5 changed files with 56 additions and 11 deletions

View File

@@ -1,8 +1,12 @@
import {
management,
ZitadelServer,
ZitadelServerOptions,
getManagement,
getServer,
getServers,
initializeServer,
LabelPolicy,
} from "@zitadel/server";
// import { getAuth } from "@zitadel/server/auth";
@@ -16,7 +20,17 @@ if (!getServers().length) {
}
const server = getServer();
console.log(server);
export function getBranding(
server: ZitadelServer
): Promise<LabelPolicy | undefined> {
const mgmt = getManagement(server);
return mgmt.getLabelPolicy({}).then((resp) => resp.policy);
}
export { server };
// export async function getMyUser(): Promise<GetMyUserResponse> {
// const auth = await getAuth();
// const response = await auth.getMyUser({});

View File

@@ -1,15 +1,34 @@
"use client";
import { getBranding } from "#/lib/zitadel";
import { useTheme } from "next-themes";
import { server } from "../lib/zitadel";
const ThemeWrapper = ({ children }: any) => {
const ThemeWrapper = async ({ children }: any) => {
const { resolvedTheme } = useTheme();
const isDark = resolvedTheme && resolvedTheme === "dark";
try {
const policy = await getBranding(server);
const backgroundStyle = {
backgroundColor: `${policy?.backgroundColorDark}.`,
};
console.log(policy);
return (
<div className={`${isDark ? "ui-dark" : "ui-light"} `}>
<div style={backgroundStyle}>{children}</div>
</div>
);
} catch (error) {
console.error(error);
return (
<div className={`${isDark ? "ui-dark" : "ui-light"} `}>{children}</div>
);
}
};
export default ThemeWrapper;

View File

@@ -1,5 +1,6 @@
export * from "./server";
export * from "./middleware";
export * from "./management";
// export * as auth from "./auth";
// export * as management from "./management";

View File

@@ -1 +1,3 @@
export * from "./management";
export * as management from "../proto/server/zitadel/management";
export * from "../proto/server/zitadel/policy";

View File

@@ -26,10 +26,19 @@ export function getServers(): ZitadelServer[] {
return apps;
}
export function getServer(name?: string): ZitadelServer | undefined {
return name
? apps.find((a) => a.name === name)
: apps.length === 1
? apps[0]
: undefined;
export function getServer(name?: string): ZitadelServer {
if (name) {
const found = apps.find((a) => a.name === name);
if (found) {
return found;
} else {
throw new Error("No server found");
}
} else {
if (apps.length) {
return apps[0];
} else {
throw new Error("No server found");
}
}
}