instance domain callback

This commit is contained in:
Max Peintner
2025-01-20 11:43:57 +01:00
parent e0a6c12231
commit f535b6da4c
2 changed files with 16 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
import { importPKCS8, SignJWT } from "jose"; import { importPKCS8, SignJWT } from "jose";
import { getInstanceByHost } from "./zitadel"; import { getInstanceDomainByHost } from "./zitadel";
export async function getInstanceUrl(host: string): Promise<string> { export async function getInstanceUrl(host: string): Promise<string> {
const [hostname, port] = host.split(":"); const [hostname, port] = host.split(":");
@@ -9,26 +9,18 @@ export async function getInstanceUrl(host: string): Promise<string> {
return process.env.ZITADEL_API_URL || ""; return process.env.ZITADEL_API_URL || "";
} }
const instance = await getInstanceByHost(host).catch((error) => { const instanceDomain = await getInstanceDomainByHost(host).catch((error) => {
console.error(`Could not get instance by host ${host}`, error); console.error(`Could not get instance by host ${host}`, error);
return null; return null;
}); });
if (!instance) { if (!instanceDomain) {
throw new Error("No instance found"); throw new Error("No instance found");
} }
const generatedDomain = instance.domains.find( console.log(`host: ${host}, api: ${instanceDomain}`);
(domain) => domain.generated === true,
);
if (!generatedDomain?.domain) { return instanceDomain;
throw new Error("No generated domain found");
}
console.log(`host: ${host}, api: ${generatedDomain?.domain}`);
return generatedDomain?.domain;
} }
export async function systemAPIToken() { export async function systemAPIToken() {

View File

@@ -66,9 +66,9 @@ const systemService = async () => {
return createSystemServiceClient(transport); return createSystemServiceClient(transport);
}; };
export async function getInstanceByHost(host: string): Promise<string> { export async function getInstanceDomainByHost(host: string): Promise<string> {
// const system = await systemService(); // const system = await systemService();
// const callback = system // const callbacks = system
// .listInstances( // .listInstances(
// { // {
// queries: [ // queries: [
@@ -89,7 +89,15 @@ export async function getInstanceByHost(host: string): Promise<string> {
// throw new Error("Could not find instance"); // throw new Error("Could not find instance");
// } // }
// return resp.result[0]; // const generatedDomain = resp.result[0].domains.find(
// (domain) => domain.generated === true,
// );
// if (!generatedDomain) {
// throw new Error("Could not find generated domain");
// }
// return generatedDomain.domain;
// }); // });
const mockFcn = async (host: string) => { const mockFcn = async (host: string) => {