idp cleanup

This commit is contained in:
Max Peintner
2024-11-18 10:41:13 +01:00
parent 2fd7cf0a61
commit 5db61c8623
2 changed files with 34 additions and 21 deletions

View File

@@ -64,17 +64,6 @@ export function SignInWithIdp({
return response;
}
async function navigateToAuthUrl(id: string, type: IdentityProviderType) {
const startFlowResponse = await startFlow(id, idpTypeToSlug(type));
if (
startFlowResponse &&
startFlowResponse.nextStep.case === "authUrl" &&
startFlowResponse?.nextStep.value
) {
router.push(startFlowResponse.nextStep.value);
}
}
return (
<div className="flex flex-col w-full space-y-2 text-sm">
{identityProviders &&
@@ -86,7 +75,7 @@ export function SignInWithIdp({
key={`idp-${i}`}
name={idp.name}
onClick={() =>
navigateToAuthUrl(idp.id, IdentityProviderType.APPLE)
startFlow(idp.id, idpTypeToSlug(IdentityProviderType.APPLE))
}
></SignInWithApple>
);
@@ -96,7 +85,7 @@ export function SignInWithIdp({
key={`idp-${i}`}
name={idp.name}
onClick={() =>
navigateToAuthUrl(idp.id, IdentityProviderType.OAUTH)
startFlow(idp.id, idpTypeToSlug(IdentityProviderType.OAUTH))
}
></SignInWithGeneric>
);
@@ -106,7 +95,7 @@ export function SignInWithIdp({
key={`idp-${i}`}
name={idp.name}
onClick={() =>
navigateToAuthUrl(idp.id, IdentityProviderType.OIDC)
startFlow(idp.id, idpTypeToSlug(IdentityProviderType.OIDC))
}
></SignInWithGeneric>
);
@@ -116,7 +105,10 @@ export function SignInWithIdp({
key={`idp-${i}`}
name={idp.name}
onClick={() =>
navigateToAuthUrl(idp.id, IdentityProviderType.GITHUB)
startFlow(
idp.id,
idpTypeToSlug(IdentityProviderType.GITHUB),
)
}
></SignInWithGithub>
);
@@ -126,7 +118,10 @@ export function SignInWithIdp({
key={`idp-${i}`}
name={idp.name}
onClick={() =>
navigateToAuthUrl(idp.id, IdentityProviderType.GITHUB_ES)
startFlow(
idp.id,
idpTypeToSlug(IdentityProviderType.GITHUB_ES),
)
}
></SignInWithGithub>
);
@@ -136,7 +131,10 @@ export function SignInWithIdp({
key={`idp-${i}`}
name={idp.name}
onClick={() =>
navigateToAuthUrl(idp.id, IdentityProviderType.AZURE_AD)
startFlow(
idp.id,
idpTypeToSlug(IdentityProviderType.AZURE_AD),
)
}
></SignInWithAzureAd>
);
@@ -147,7 +145,10 @@ export function SignInWithIdp({
e2e="google"
name={idp.name}
onClick={() =>
navigateToAuthUrl(idp.id, IdentityProviderType.GOOGLE)
startFlow(
idp.id,
idpTypeToSlug(IdentityProviderType.GOOGLE),
)
}
></SignInWithGoogle>
);
@@ -157,7 +158,10 @@ export function SignInWithIdp({
key={`idp-${i}`}
name={idp.name}
onClick={() =>
navigateToAuthUrl(idp.id, IdentityProviderType.GITLAB)
startFlow(
idp.id,
idpTypeToSlug(IdentityProviderType.GITLAB),
)
}
></SignInWithGitlab>
);
@@ -167,9 +171,9 @@ export function SignInWithIdp({
key={`idp-${i}`}
name={idp.name}
onClick={() =>
navigateToAuthUrl(
startFlow(
idp.id,
IdentityProviderType.GITLAB_SELF_HOSTED,
idpTypeToSlug(IdentityProviderType.GITLAB_SELF_HOSTED),
)
}
></SignInWithGitlab>

View File

@@ -1,6 +1,7 @@
"use server";
import { startIdentityProviderFlow } from "@/lib/zitadel";
import { redirect } from "next/navigation";
export type StartIDPFlowCommand = {
idpId: string;
@@ -15,5 +16,13 @@ export async function startIDPFlow(command: StartIDPFlowCommand) {
successUrl: command.successUrl,
failureUrl: command.failureUrl,
},
}).then((response) => {
if (
response &&
response.nextStep.case === "authUrl" &&
response?.nextStep.value
) {
return redirect(response.nextStep.value);
}
});
}