mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 07:24:51 +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 }) {
|
export default async function Page({ searchParams }: { searchParams: any }) {
|
||||||
const {
|
const {
|
||||||
userID,
|
userId,
|
||||||
|
sessionId,
|
||||||
code,
|
code,
|
||||||
submit,
|
submit,
|
||||||
organization,
|
organization,
|
||||||
@@ -31,6 +32,7 @@ export default async function Page({ searchParams }: { searchParams: any }) {
|
|||||||
submit={submit === "true"}
|
submit={submit === "true"}
|
||||||
organization={organization}
|
organization={organization}
|
||||||
authRequestId={authRequestId}
|
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">
|
<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 { addHumanUser, server } from "#/lib/zitadel";
|
||||||
|
import {
|
||||||
|
createSessionAndUpdateCookie,
|
||||||
|
createSessionForUserIdAndUpdateCookie,
|
||||||
|
} from "#/utils/session";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
@@ -20,8 +24,18 @@ export async function POST(request: NextRequest) {
|
|||||||
password: password ? password : undefined,
|
password: password ? password : undefined,
|
||||||
organization,
|
organization,
|
||||||
})
|
})
|
||||||
.then((userId) => {
|
.then((user) => {
|
||||||
return NextResponse.json({ userId });
|
return createSessionForUserIdAndUpdateCookie(
|
||||||
|
user.userId,
|
||||||
|
password,
|
||||||
|
undefined,
|
||||||
|
authRequestId
|
||||||
|
).then((session) => {
|
||||||
|
return NextResponse.json({
|
||||||
|
userId: user.userId,
|
||||||
|
sessionId: session.id,
|
||||||
|
});
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
return NextResponse.json(error, { status: 500 });
|
return NextResponse.json(error, { status: 500 });
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { stub } from "../support/mock";
|
|||||||
describe("/verify", () => {
|
describe("/verify", () => {
|
||||||
it("redirects after successful email verification", () => {
|
it("redirects after successful email verification", () => {
|
||||||
stub("zitadel.user.v2beta.UserService", "VerifyEmail");
|
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");
|
cy.location("pathname", { timeout: 10_000 }).should("eq", "/loginname");
|
||||||
});
|
});
|
||||||
it("shows an error if validation failed", () => {
|
it("shows an error if validation failed", () => {
|
||||||
@@ -13,7 +13,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");
|
||||||
cy.contains("error validating code");
|
cy.contains("error validating code");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ export type AddHumanUserData = {
|
|||||||
export async function addHumanUser(
|
export async function addHumanUser(
|
||||||
server: ZitadelServer,
|
server: ZitadelServer,
|
||||||
{ email, firstName, lastName, password, organization }: AddHumanUserData
|
{ email, firstName, lastName, password, organization }: AddHumanUserData
|
||||||
): Promise<string> {
|
): Promise<AddHumanUserResponse> {
|
||||||
const userService = user.getUser(server);
|
const userService = user.getUser(server);
|
||||||
|
|
||||||
const payload: Partial<AddHumanUserRequest> = {
|
const payload: Partial<AddHumanUserRequest> = {
|
||||||
@@ -284,19 +284,15 @@ export async function addHumanUser(
|
|||||||
payload.organization = { orgId: organization };
|
payload.organization = { orgId: organization };
|
||||||
}
|
}
|
||||||
|
|
||||||
return userService
|
return userService.addHumanUser(
|
||||||
.addHumanUser(
|
password
|
||||||
password
|
? {
|
||||||
? {
|
...payload,
|
||||||
...payload,
|
password: { password },
|
||||||
password: { password },
|
}
|
||||||
}
|
: payload,
|
||||||
: payload,
|
{}
|
||||||
{}
|
);
|
||||||
)
|
|
||||||
.then((resp: AddHumanUserResponse) => {
|
|
||||||
return resp.userId;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listUsers(
|
export async function listUsers(
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export default function RegisterForm({
|
|||||||
|
|
||||||
function submitAndLink(value: Inputs): Promise<boolean | void> {
|
function submitAndLink(value: Inputs): Promise<boolean | void> {
|
||||||
return submitRegister(value).then((resp: any) => {
|
return submitRegister(value).then((resp: any) => {
|
||||||
const params: any = { userID: resp.userId };
|
const params: any = { userId: resp.userId };
|
||||||
|
|
||||||
if (organization) {
|
if (organization) {
|
||||||
params.organization = organization;
|
params.organization = organization;
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ export default function SetPasswordForm({
|
|||||||
return createSessionWithLoginNameAndPassword(
|
return createSessionWithLoginNameAndPassword(
|
||||||
email,
|
email,
|
||||||
value.password
|
value.password
|
||||||
).then(() => {
|
).then((session) => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
const params: any = { userID: humanResponse.userId };
|
const params: any = { userID: humanResponse.userId };
|
||||||
|
|
||||||
@@ -114,6 +114,9 @@ export default function SetPasswordForm({
|
|||||||
if (organization) {
|
if (organization) {
|
||||||
params.organization = organization;
|
params.organization = organization;
|
||||||
}
|
}
|
||||||
|
if (session && session.sessionId) {
|
||||||
|
params.sessionId = session.sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
return router.push(`/verify?` + new URLSearchParams(params));
|
return router.push(`/verify?` + new URLSearchParams(params));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ type Props = {
|
|||||||
submit: boolean;
|
submit: boolean;
|
||||||
organization?: string;
|
organization?: string;
|
||||||
authRequestId?: string;
|
authRequestId?: string;
|
||||||
|
sessionId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function VerifyEmailForm({
|
export default function VerifyEmailForm({
|
||||||
@@ -26,6 +27,7 @@ export default function VerifyEmailForm({
|
|||||||
submit,
|
submit,
|
||||||
organization,
|
organization,
|
||||||
authRequestId,
|
authRequestId,
|
||||||
|
sessionId,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const { register, handleSubmit, formState } = useForm<Inputs>({
|
const { register, handleSubmit, formState } = useForm<Inputs>({
|
||||||
mode: "onBlur",
|
mode: "onBlur",
|
||||||
@@ -96,7 +98,19 @@ export default function VerifyEmailForm({
|
|||||||
|
|
||||||
function submitCodeAndContinue(value: Inputs): Promise<boolean | void> {
|
function submitCodeAndContinue(value: Inputs): Promise<boolean | void> {
|
||||||
return submitCode(value).then((resp: any) => {
|
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