show authenticator button if no method set yet

This commit is contained in:
Max Peintner
2024-10-25 10:07:48 +02:00
parent 1c65dbdb9a
commit 5fd72f5388
6 changed files with 40 additions and 3 deletions

View File

@@ -156,6 +156,7 @@
"verify": {
"userIdMissing": "Keine Benutzer-ID angegeben!",
"success": "Erfolgreich verifiziert",
"setupAuthenticator": "Authentifikator einrichten",
"verify": {
"title": "Benutzer verifizieren",
"description": "Geben Sie den Code ein, der in der Bestätigungs-E-Mail angegeben ist.",

View File

@@ -156,6 +156,7 @@
"verify": {
"userIdMissing": "No userId provided!",
"success": "The user has been verified successfully.",
"setupAuthenticator": "Setup authenticator",
"verify": {
"title": "Verify user",
"description": "Enter the Code provided in the verification email.",

View File

@@ -156,6 +156,7 @@
"verify": {
"userIdMissing": "¡No se proporcionó userId!",
"success": "¡Verificación exitosa!",
"setupAuthenticator": "Configurar autenticador",
"verify": {
"title": "Verificar usuario",
"description": "Introduce el código proporcionado en el correo electrónico de verificación.",

View File

@@ -156,6 +156,7 @@
"verify": {
"userIdMissing": "Nessun userId fornito!",
"success": "Verifica effettuata con successo!",
"setupAuthenticator": "Configura autenticatore",
"verify": {
"title": "Verifica utente",
"description": "Inserisci il codice fornito nell'email di verifica.",

View File

@@ -120,7 +120,6 @@ export default async function Page({
{loginSettings && sessionWithData && (
<ChooseAuthenticatorToSetup
authMethods={sessionWithData.authMethods}
sessionFactors={sessionWithData.factors}
loginSettings={loginSettings}
params={params}
></ChooseAuthenticatorToSetup>

View File

@@ -1,10 +1,18 @@
import { Alert, AlertType } from "@/components/alert";
import { BackButton } from "@/components/back-button";
import { Button, ButtonVariants } from "@/components/button";
import { DynamicTheme } from "@/components/dynamic-theme";
import { UserAvatar } from "@/components/user-avatar";
import { VerifyForm } from "@/components/verify-form";
import { getBrandingSettings, getUserByID } from "@/lib/zitadel";
import {
getBrandingSettings,
getUserByID,
listAuthenticationMethodTypes,
} from "@/lib/zitadel";
import { HumanUser, User } from "@zitadel/proto/zitadel/user/v2/user_pb";
import { AuthenticationMethodType } from "@zitadel/proto/zitadel/user/v2/user_service_pb";
import { getLocale, getTranslations } from "next-intl/server";
import Link from "next/link";
export default async function Page({ searchParams }: { searchParams: any }) {
const locale = getLocale();
@@ -28,6 +36,14 @@ export default async function Page({ searchParams }: { searchParams: any }) {
}
}
let authMethods: AuthenticationMethodType[] | null = null;
if (human?.email?.isVerified) {
const authMethodsResponse = await listAuthenticationMethodTypes(userId);
if (authMethodsResponse.authMethodTypes) {
authMethods = authMethodsResponse.authMethodTypes;
}
}
const params = new URLSearchParams({
userId: userId,
initial: "true", // defines that a code is not required and is therefore not shown in the UI
@@ -70,7 +86,25 @@ export default async function Page({ searchParams }: { searchParams: any }) {
/>
)}
{human?.email?.isVerified ? (
<Alert type={AlertType.INFO}>{t("success")}</Alert>
<>
<Alert type={AlertType.INFO}>{t("success")}</Alert>
<div className="mt-8 flex w-full flex-row items-center">
<BackButton />
<span className="flex-grow"></span>
{authMethods?.length !== 0 && (
<Link href={`/authenticator/set?+${params}`}>
<Button
type="submit"
className="self-end"
variant={ButtonVariants.Primary}
>
{t("setupAuthenticator")}
</Button>
</Link>
)}
</div>
</>
) : (
// check if auth methods are set
<VerifyForm