Files
zitadel/packages/zitadel-client/src/auth.ts

26 lines
790 B
TypeScript
Raw Normal View History

2023-04-06 18:57:58 +02:00
import { CompatServiceDefinition } from "nice-grpc/lib/service-definitions";
import { createChannel, createClientFactory } from "nice-grpc";
import {
AuthServiceClient,
AuthServiceDefinition,
} from "./proto/server/zitadel/auth";
2023-04-13 13:26:02 +02:00
import { ZitadelApp } from "./app";
2023-04-06 18:57:58 +02:00
import { authMiddleware } from "./middleware";
const createClient = <Client>(
definition: CompatServiceDefinition,
accessToken: string
) => {
2023-04-13 13:26:02 +02:00
const channel = createChannel(process.env.ZITADEL_API_URL ?? "");
2023-04-06 18:57:58 +02:00
return createClientFactory()
.use(authMiddleware(accessToken))
.create(definition, channel) as Client;
};
export async function getAuth(app?: ZitadelApp): Promise<AuthServiceClient> {
2023-04-13 13:26:02 +02:00
return createClient<AuthServiceClient>(
AuthServiceDefinition as CompatServiceDefinition,
""
);
2023-04-06 18:57:58 +02:00
}