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