Files
zitadel/apps/login/app/passkeys/route.ts

45 lines
1.2 KiB
TypeScript
Raw Normal View History

import {
createPasskeyRegistrationLink,
getSession,
server,
} from "#/lib/zitadel";
import { getSessionCookieById } from "#/utils/cookies";
import { NextRequest, NextResponse } from "next/server";
export async function POST(request: NextRequest) {
const body = await request.json();
if (body) {
const { sessionId } = body;
2023-06-08 17:27:35 +02:00
const sessionCookie = await getSessionCookieById(sessionId);
console.log(sessionCookie);
2023-06-08 17:27:35 +02:00
const session = await getSession(
server,
sessionCookie.id,
sessionCookie.token
);
if (session?.session && session.session?.factors?.user?.id) {
console.log(session.session.factors.user.id, sessionCookie.token);
return createPasskeyRegistrationLink(
session.session.factors.user.id,
sessionCookie.token
)
.then((resp) => {
return NextResponse.json(resp);
})
.catch((error) => {
return NextResponse.json(error, { status: 500 });
});
} else {
return NextResponse.json(
{ details: "could not get session" },
{ status: 500 }
);
}
} else {
return NextResponse.json({}, { status: 500 });
}
}