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