mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-15 18:12:16 +00:00
35 lines
888 B
TypeScript
35 lines
888 B
TypeScript
"use server";
|
|
|
|
import { startIdentityProviderFlow } from "@/lib/zitadel";
|
|
import { headers } from "next/headers";
|
|
|
|
export type StartIDPFlowCommand = {
|
|
idpId: string;
|
|
successUrl: string;
|
|
failureUrl: string;
|
|
};
|
|
|
|
export async function startIDPFlow(command: StartIDPFlowCommand) {
|
|
const host = (await headers()).get("host");
|
|
|
|
if (!host) {
|
|
return { error: "Could not get host" };
|
|
}
|
|
|
|
return startIdentityProviderFlow({
|
|
idpId: command.idpId,
|
|
urls: {
|
|
successUrl: `${host.includes("localhost") ? "http://" : "https://"}${host}${command.successUrl}`,
|
|
failureUrl: `${host.includes("localhost") ? "http://" : "https://"}${host}${command.failureUrl}`,
|
|
},
|
|
}).then((response) => {
|
|
if (
|
|
response &&
|
|
response.nextStep.case === "authUrl" &&
|
|
response?.nextStep.value
|
|
) {
|
|
return { redirect: response.nextStep.value };
|
|
}
|
|
});
|
|
}
|