redirect to totp from password form

This commit is contained in:
peintnermax
2024-04-04 15:44:02 +02:00
parent d7f7fef200
commit 57e4585120
2 changed files with 19 additions and 0 deletions

View File

@@ -98,8 +98,10 @@ export async function PUT(request: NextRequest) {
password, password,
webAuthN, webAuthN,
challenges, challenges,
undefined,
authRequestId authRequestId
).then((session) => { ).then((session) => {
console.log(session);
return NextResponse.json({ return NextResponse.json({
sessionId: session.id, sessionId: session.id,
factors: session.factors, factors: session.factors,

View File

@@ -7,12 +7,14 @@ import { useForm } from "react-hook-form";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { Spinner } from "./Spinner"; import { Spinner } from "./Spinner";
import Alert from "./Alert"; import Alert from "./Alert";
import { LoginSettings } from "@zitadel/server";
type Inputs = { type Inputs = {
password: string; password: string;
}; };
type Props = { type Props = {
loginSettings: LoginSettings | undefined;
loginName?: string; loginName?: string;
organization?: string; organization?: string;
authRequestId?: string; authRequestId?: string;
@@ -21,6 +23,7 @@ type Props = {
}; };
export default function PasswordForm({ export default function PasswordForm({
loginSettings,
loginName, loginName,
organization, organization,
authRequestId, authRequestId,
@@ -83,6 +86,19 @@ export default function PasswordForm({
return router.push(`/passkey/add?` + params); return router.push(`/passkey/add?` + params);
} else { } else {
let continueWithMfa = undefined;
if (
loginSettings?.forceMfa &&
loginSettings.secondFactors?.length >= 1 // TODO replace with user methods - if forceMFA is set and no user methods prompt to add method (/mfa/add)
) {
if (loginSettings.secondFactors?.length === 1) {
continueWithMfa = loginSettings.secondFactors[0];
} else {
// continueWithMfa = loginSettings.secondFactors[0];
// render selection page for mfa (/mfa/select)
}
}
// OIDC flows
if (authRequestId && resp && resp.sessionId) { if (authRequestId && resp && resp.sessionId) {
const params = new URLSearchParams({ const params = new URLSearchParams({
sessionId: resp.sessionId, sessionId: resp.sessionId,
@@ -95,6 +111,7 @@ export default function PasswordForm({
return router.push(`/login?` + params); return router.push(`/login?` + params);
} else { } else {
// without OIDC flow
const params = new URLSearchParams( const params = new URLSearchParams(
authRequestId authRequestId
? { ? {