mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 10:15:04 +00:00
set session cleanup
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
createSessionAndUpdateCookie,
|
||||
setSessionAndUpdateCookie,
|
||||
} from "#/utils/session";
|
||||
import { RequestChallenges } from "@zitadel/server";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
@@ -17,7 +18,7 @@ export async function POST(request: NextRequest) {
|
||||
if (body) {
|
||||
const { loginName, password } = body;
|
||||
|
||||
const domain: string = request.nextUrl.hostname;
|
||||
// const domain: string = request.nextUrl.hostname;
|
||||
|
||||
return createSessionAndUpdateCookie(
|
||||
loginName,
|
||||
@@ -44,7 +45,8 @@ export async function PUT(request: NextRequest) {
|
||||
const body = await request.json();
|
||||
|
||||
if (body) {
|
||||
const { loginName, password, challenges, passkey, authRequestId } = body;
|
||||
const { loginName, password, passkey, authRequestId } = body;
|
||||
const challenges: RequestChallenges = body.challenges;
|
||||
|
||||
const recentPromise: Promise<SessionCookie> = loginName
|
||||
? getSessionCookieByLoginName(loginName).catch((error) => {
|
||||
@@ -54,7 +56,11 @@ export async function PUT(request: NextRequest) {
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
// const domain: string = request.nextUrl.hostname;
|
||||
const domain: string = request.nextUrl.hostname;
|
||||
|
||||
if (challenges.webAuthN && !challenges.webAuthN.domain) {
|
||||
challenges.webAuthN.domain = domain;
|
||||
}
|
||||
|
||||
return recentPromise
|
||||
.then((recent) => {
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
GetSessionResponse,
|
||||
VerifyEmailResponse,
|
||||
SetSessionResponse,
|
||||
SetSessionRequest,
|
||||
DeleteSessionResponse,
|
||||
VerifyPasskeyRegistrationResponse,
|
||||
LoginSettings,
|
||||
@@ -129,16 +130,23 @@ export async function setSession(
|
||||
): Promise<SetSessionResponse | undefined> {
|
||||
const sessionService = session.getSession(server);
|
||||
|
||||
const payload = { sessionId, sessionToken, challenges };
|
||||
return password
|
||||
? sessionService.setSession(
|
||||
{
|
||||
...payload,
|
||||
checks: { password: { password }, webAuthN },
|
||||
},
|
||||
{}
|
||||
)
|
||||
: sessionService.setSession(payload, {});
|
||||
const payload: SetSessionRequest = {
|
||||
sessionId,
|
||||
sessionToken,
|
||||
challenges,
|
||||
checks: {},
|
||||
metadata: {},
|
||||
};
|
||||
|
||||
if (password && payload.checks) {
|
||||
payload.checks.password = { password };
|
||||
}
|
||||
|
||||
if (webAuthN && payload.checks) {
|
||||
payload.checks.webAuthN = webAuthN;
|
||||
}
|
||||
|
||||
return sessionService.setSession(payload, {});
|
||||
}
|
||||
|
||||
export async function getSession(
|
||||
|
||||
@@ -31,6 +31,7 @@ export default function LoginPasskey({
|
||||
setLoading(true);
|
||||
updateSessionForChallenge()
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
const pK =
|
||||
response.challenges.passkey.publicKeyCredentialRequestOptions
|
||||
.publicKey;
|
||||
@@ -64,7 +65,12 @@ export default function LoginPasskey({
|
||||
},
|
||||
body: JSON.stringify({
|
||||
loginName,
|
||||
challenges: [1], // request passkey challenge
|
||||
challenges: {
|
||||
webAuthN: {
|
||||
domain: "",
|
||||
userVerificationRequirement: 2,
|
||||
},
|
||||
},
|
||||
authRequestId,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -62,6 +62,7 @@ export async function setSessionAndUpdateCookie(
|
||||
challenges: RequestChallenges | undefined,
|
||||
authRequestId: string | undefined
|
||||
): Promise<SessionWithChallenges> {
|
||||
console.log(password, passkey, challenges);
|
||||
return setSession(
|
||||
server,
|
||||
sessionId,
|
||||
|
||||
@@ -45,6 +45,7 @@ export {
|
||||
GetSessionResponse,
|
||||
CreateSessionResponse,
|
||||
SetSessionResponse,
|
||||
SetSessionRequest,
|
||||
DeleteSessionResponse,
|
||||
} from "./proto/server/zitadel/session/v2alpha/session_service";
|
||||
export {
|
||||
|
||||
Reference in New Issue
Block a user