mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-13 21:40:45 +00:00
chore: move app code into src dir
This commit is contained in:
50
apps/login/src/app/api/u2f/verify/route.ts
Normal file
50
apps/login/src/app/api/u2f/verify/route.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { getSession, server, verifyU2FRegistration } from "@/lib/zitadel";
|
||||
import { getSessionCookieById } from "@/utils/cookies";
|
||||
import { VerifyU2FRegistrationRequest } from "@zitadel/server";
|
||||
import { NextRequest, NextResponse, userAgent } from "next/server";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const body = await request.json();
|
||||
if (body) {
|
||||
let { u2fId, passkeyName, publicKeyCredential, sessionId } = body;
|
||||
|
||||
if (!!!passkeyName) {
|
||||
const { browser, device, os } = userAgent(request);
|
||||
passkeyName = `${device.vendor ?? ""} ${device.model ?? ""}${
|
||||
device.vendor || device.model ? ", " : ""
|
||||
}${os.name}${os.name ? ", " : ""}${browser.name}`;
|
||||
}
|
||||
const sessionCookie = await getSessionCookieById(sessionId);
|
||||
|
||||
const session = await getSession(
|
||||
server,
|
||||
sessionCookie.id,
|
||||
sessionCookie.token,
|
||||
);
|
||||
|
||||
const userId = session?.session?.factors?.user?.id;
|
||||
|
||||
if (userId) {
|
||||
const req: VerifyU2FRegistrationRequest = {
|
||||
publicKeyCredential,
|
||||
u2fId,
|
||||
userId,
|
||||
tokenName: passkeyName,
|
||||
};
|
||||
return verifyU2FRegistration(req)
|
||||
.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: 400 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user