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 { import {
management,
ZitadelServer,
ZitadelServerOptions, ZitadelServerOptions,
getManagement,
getServer, getServer,
getServers, getServers,
initializeServer, initializeServer,
LabelPolicy,
} from "@zitadel/server"; } from "@zitadel/server";
// import { getAuth } from "@zitadel/server/auth"; // import { getAuth } from "@zitadel/server/auth";
@@ -16,7 +20,17 @@ if (!getServers().length) {
} }
const server = getServer(); 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> { // export async function getMyUser(): Promise<GetMyUserResponse> {
// const auth = await getAuth(); // const auth = await getAuth();
// const response = await auth.getMyUser({}); // const response = await auth.getMyUser({});

View File

@@ -1,15 +1,34 @@
"use client"; "use client";
import { getBranding } from "#/lib/zitadel";
import { useTheme } from "next-themes"; import { useTheme } from "next-themes";
import { server } from "../lib/zitadel";
const ThemeWrapper = ({ children }: any) => { const ThemeWrapper = async ({ children }: any) => {
const { resolvedTheme } = useTheme(); const { resolvedTheme } = useTheme();
const isDark = resolvedTheme && resolvedTheme === "dark"; const isDark = resolvedTheme && resolvedTheme === "dark";
return ( try {
<div className={`${isDark ? "ui-dark" : "ui-light"} `}>{children}</div> 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; export default ThemeWrapper;

View File

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

View File

@@ -1 +1,3 @@
export * from "./management"; 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; return apps;
} }
export function getServer(name?: string): ZitadelServer | undefined { export function getServer(name?: string): ZitadelServer {
return name if (name) {
? apps.find((a) => a.name === name) const found = apps.find((a) => a.name === name);
: apps.length === 1 if (found) {
? apps[0] return found;
: undefined; } else {
throw new Error("No server found");
}
} else {
if (apps.length) {
return apps[0];
} else {
throw new Error("No server found");
}
}
} }