pass sessionid on verify, create session for created user

This commit is contained in:
peintnermax
2024-04-01 15:03:41 +02:00
parent 3fedba45df
commit 6a52a8809c
7 changed files with 51 additions and 22 deletions

View File

@@ -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">

View File

@@ -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 });