mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 01:52:54 +00:00
redirect from server action
This commit is contained in:
@@ -4,8 +4,10 @@ describe("/verify", () => {
|
||||
it("shows password and passkey method after successful invite verification", () => {
|
||||
stub("zitadel.user.v2.UserService", "VerifyEmail");
|
||||
cy.visit("/verify?userId=123&code=abc&submit=true&invite=true");
|
||||
cy.contains("Password");
|
||||
cy.contains("Passkey");
|
||||
cy.location("pathname", { timeout: 10_000 }).should(
|
||||
"eq",
|
||||
"/authenticator/set",
|
||||
);
|
||||
});
|
||||
it("shows an error if validation failed", () => {
|
||||
stub("zitadel.user.v2.UserService", "VerifyEmail", {
|
||||
@@ -14,7 +16,7 @@ describe("/verify", () => {
|
||||
});
|
||||
// TODO: Avoid uncaught exception in application
|
||||
cy.once("uncaught:exception", () => false);
|
||||
cy.visit("/verify?userId=123&code=abc&submit=true");
|
||||
cy.visit("/verify?userId=123&code=abc&submit=true&invite=true");
|
||||
cy.contains("Could not verify user");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -58,6 +58,7 @@ export function InviteForm({
|
||||
}).catch(() => {
|
||||
setError("Could not create invitation Code");
|
||||
setLoading(false);
|
||||
return;
|
||||
});
|
||||
|
||||
setLoading(false);
|
||||
@@ -69,6 +70,7 @@ export function InviteForm({
|
||||
|
||||
if (!response) {
|
||||
setError("Could not create invitation Code");
|
||||
return;
|
||||
}
|
||||
|
||||
const params = new URLSearchParams({});
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
verifyUserAndCreateSession,
|
||||
} from "@/lib/server/email";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useRouter } from "next/router";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { Button, ButtonVariants } from "./button";
|
||||
@@ -65,6 +65,7 @@ export function VerifyForm({ userId, code, isInvite, params }: Props) {
|
||||
userId,
|
||||
isInvite: isInvite,
|
||||
}).catch(() => {
|
||||
console.log(error);
|
||||
setError("Could not verify email");
|
||||
setLoading(false);
|
||||
return;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import {
|
||||
getUserByID,
|
||||
listAuthenticationMethodTypes,
|
||||
resendEmailCode,
|
||||
resendInviteCode,
|
||||
verifyEmail,
|
||||
@@ -9,6 +10,7 @@ import {
|
||||
} from "@/lib/zitadel";
|
||||
import { create } from "@zitadel/client";
|
||||
import { ChecksSchema } from "@zitadel/proto/zitadel/session/v2/session_service_pb";
|
||||
import { redirect } from "next/navigation";
|
||||
import { createSessionAndUpdateCookie } from "./cookie";
|
||||
|
||||
type VerifyUserByEmailCommand = {
|
||||
@@ -54,10 +56,37 @@ export async function verifyUserAndCreateSession(
|
||||
command.authRequestId,
|
||||
);
|
||||
|
||||
return {
|
||||
const authMethodResponse = await listAuthenticationMethodTypes(
|
||||
command.userId,
|
||||
);
|
||||
|
||||
if (!authMethodResponse || !authMethodResponse.authMethodTypes) {
|
||||
return { error: "Could not load possible authenticators" };
|
||||
}
|
||||
console.log("xs");
|
||||
// if no authmethods are found on the user, redirect to set one up
|
||||
if (
|
||||
authMethodResponse &&
|
||||
authMethodResponse.authMethodTypes &&
|
||||
authMethodResponse.authMethodTypes.length == 0
|
||||
) {
|
||||
const params = new URLSearchParams({
|
||||
sessionId: session.id,
|
||||
factors: session.factors,
|
||||
};
|
||||
});
|
||||
|
||||
if (session.factors?.user?.loginName) {
|
||||
params.set("loginName", session.factors?.user?.loginName);
|
||||
}
|
||||
|
||||
console.log("/authenticator/set?" + params);
|
||||
return redirect("/authenticator/set?" + params);
|
||||
}
|
||||
|
||||
// return {
|
||||
// authMethodTypes: authMethodResponse.authMethodTypes,
|
||||
// sessionId: session.id,
|
||||
// factors: session.factors,
|
||||
// };
|
||||
}
|
||||
|
||||
type resendVerifyEmailCommand = {
|
||||
|
||||
Reference in New Issue
Block a user