mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 05:44:36 +00:00
pass sessionid on verify, create session for created user
This commit is contained in:
@@ -5,7 +5,8 @@ import { ExclamationTriangleIcon } from "@heroicons/react/24/outline";
|
||||
|
||||
export default async function Page({ searchParams }: { searchParams: any }) {
|
||||
const {
|
||||
userID,
|
||||
userId,
|
||||
sessionId,
|
||||
code,
|
||||
submit,
|
||||
organization,
|
||||
@@ -31,6 +32,7 @@ export default async function Page({ searchParams }: { searchParams: any }) {
|
||||
submit={submit === "true"}
|
||||
organization={organization}
|
||||
authRequestId={authRequestId}
|
||||
sessionId={sessionId}
|
||||
/>
|
||||
) : (
|
||||
<div className="w-full flex flex-row items-center justify-center border border-yellow-600/40 dark:border-yellow-500/20 bg-yellow-200/30 text-yellow-600 dark:bg-yellow-700/20 dark:text-yellow-200 rounded-md py-2 scroll-px-40">
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { addHumanUser, server } from "#/lib/zitadel";
|
||||
import {
|
||||
createSessionAndUpdateCookie,
|
||||
createSessionForUserIdAndUpdateCookie,
|
||||
} from "#/utils/session";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
@@ -20,8 +24,18 @@ export async function POST(request: NextRequest) {
|
||||
password: password ? password : undefined,
|
||||
organization,
|
||||
})
|
||||
.then((userId) => {
|
||||
return NextResponse.json({ userId });
|
||||
.then((user) => {
|
||||
return createSessionForUserIdAndUpdateCookie(
|
||||
user.userId,
|
||||
password,
|
||||
undefined,
|
||||
authRequestId
|
||||
).then((session) => {
|
||||
return NextResponse.json({
|
||||
userId: user.userId,
|
||||
sessionId: session.id,
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
return NextResponse.json(error, { status: 500 });
|
||||
|
||||
@@ -3,7 +3,7 @@ import { stub } from "../support/mock";
|
||||
describe("/verify", () => {
|
||||
it("redirects after successful email verification", () => {
|
||||
stub("zitadel.user.v2beta.UserService", "VerifyEmail");
|
||||
cy.visit("/verify?userID=123&code=abc&submit=true");
|
||||
cy.visit("/verify?userId=123&code=abc&submit=true");
|
||||
cy.location("pathname", { timeout: 10_000 }).should("eq", "/loginname");
|
||||
});
|
||||
it("shows an error if validation failed", () => {
|
||||
@@ -13,7 +13,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");
|
||||
cy.contains("error validating code");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -271,7 +271,7 @@ export type AddHumanUserData = {
|
||||
export async function addHumanUser(
|
||||
server: ZitadelServer,
|
||||
{ email, firstName, lastName, password, organization }: AddHumanUserData
|
||||
): Promise<string> {
|
||||
): Promise<AddHumanUserResponse> {
|
||||
const userService = user.getUser(server);
|
||||
|
||||
const payload: Partial<AddHumanUserRequest> = {
|
||||
@@ -284,19 +284,15 @@ export async function addHumanUser(
|
||||
payload.organization = { orgId: organization };
|
||||
}
|
||||
|
||||
return userService
|
||||
.addHumanUser(
|
||||
password
|
||||
? {
|
||||
...payload,
|
||||
password: { password },
|
||||
}
|
||||
: payload,
|
||||
{}
|
||||
)
|
||||
.then((resp: AddHumanUserResponse) => {
|
||||
return resp.userId;
|
||||
});
|
||||
return userService.addHumanUser(
|
||||
password
|
||||
? {
|
||||
...payload,
|
||||
password: { password },
|
||||
}
|
||||
: payload,
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
export async function listUsers(
|
||||
|
||||
@@ -78,7 +78,7 @@ export default function RegisterForm({
|
||||
|
||||
function submitAndLink(value: Inputs): Promise<boolean | void> {
|
||||
return submitRegister(value).then((resp: any) => {
|
||||
const params: any = { userID: resp.userId };
|
||||
const params: any = { userId: resp.userId };
|
||||
|
||||
if (organization) {
|
||||
params.organization = organization;
|
||||
|
||||
@@ -104,7 +104,7 @@ export default function SetPasswordForm({
|
||||
return createSessionWithLoginNameAndPassword(
|
||||
email,
|
||||
value.password
|
||||
).then(() => {
|
||||
).then((session) => {
|
||||
setLoading(false);
|
||||
const params: any = { userID: humanResponse.userId };
|
||||
|
||||
@@ -114,6 +114,9 @@ export default function SetPasswordForm({
|
||||
if (organization) {
|
||||
params.organization = organization;
|
||||
}
|
||||
if (session && session.sessionId) {
|
||||
params.sessionId = session.sessionId;
|
||||
}
|
||||
|
||||
return router.push(`/verify?` + new URLSearchParams(params));
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@ type Props = {
|
||||
submit: boolean;
|
||||
organization?: string;
|
||||
authRequestId?: string;
|
||||
sessionId?: string;
|
||||
};
|
||||
|
||||
export default function VerifyEmailForm({
|
||||
@@ -26,6 +27,7 @@ export default function VerifyEmailForm({
|
||||
submit,
|
||||
organization,
|
||||
authRequestId,
|
||||
sessionId,
|
||||
}: Props) {
|
||||
const { register, handleSubmit, formState } = useForm<Inputs>({
|
||||
mode: "onBlur",
|
||||
@@ -96,7 +98,19 @@ export default function VerifyEmailForm({
|
||||
|
||||
function submitCodeAndContinue(value: Inputs): Promise<boolean | void> {
|
||||
return submitCode(value).then((resp: any) => {
|
||||
return router.push(`/loginname`);
|
||||
const params = new URLSearchParams({});
|
||||
|
||||
if (organization) {
|
||||
params.set("organization", organization);
|
||||
}
|
||||
|
||||
if (authRequestId && sessionId) {
|
||||
params.set("authRequest", authRequestId);
|
||||
params.set("sessionId", sessionId);
|
||||
return router.push(`/login?` + params);
|
||||
} else {
|
||||
return router.push(`/loginname?` + params);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user