mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 09:54:00 +00:00
cleanup sessions based on expiration date
This commit is contained in:
@@ -130,10 +130,10 @@ export async function createSessionForLoginname(
|
|||||||
{
|
{
|
||||||
checks: { user: { loginName }, password: { password } },
|
checks: { user: { loginName }, password: { password } },
|
||||||
challenges,
|
challenges,
|
||||||
// lifetime: {
|
lifetime: {
|
||||||
// seconds: 300,
|
seconds: 300,
|
||||||
// nanos: 0,
|
nanos: 0,
|
||||||
// },
|
},
|
||||||
},
|
},
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
@@ -141,10 +141,10 @@ export async function createSessionForLoginname(
|
|||||||
{
|
{
|
||||||
checks: { user: { loginName } },
|
checks: { user: { loginName } },
|
||||||
challenges,
|
challenges,
|
||||||
// lifetime: {
|
lifetime: {
|
||||||
// seconds: 300,
|
seconds: 300,
|
||||||
// nanos: 0,
|
nanos: 0,
|
||||||
// },
|
},
|
||||||
},
|
},
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
@@ -162,10 +162,10 @@ export async function createSessionForUserId(
|
|||||||
{
|
{
|
||||||
checks: { user: { userId }, password: { password } },
|
checks: { user: { userId }, password: { password } },
|
||||||
challenges,
|
challenges,
|
||||||
// lifetime: {
|
lifetime: {
|
||||||
// seconds: 300,
|
seconds: 300,
|
||||||
// nanos: 0,
|
nanos: 0,
|
||||||
// },
|
},
|
||||||
},
|
},
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
@@ -173,10 +173,10 @@ export async function createSessionForUserId(
|
|||||||
{
|
{
|
||||||
checks: { user: { userId } },
|
checks: { user: { userId } },
|
||||||
challenges,
|
challenges,
|
||||||
// lifetime: {
|
lifetime: {
|
||||||
// seconds: 300,
|
seconds: 300,
|
||||||
// nanos: 0,
|
nanos: 0,
|
||||||
// },
|
},
|
||||||
},
|
},
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -45,15 +45,15 @@ export async function addSessionToCookie(
|
|||||||
currentSessions = [...currentSessions, session];
|
currentSessions = [...currentSessions, session];
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (cleanup) {
|
if (cleanup) {
|
||||||
// const now = new Date();
|
const now = new Date();
|
||||||
// const filteredSessions = currentSessions.filter(
|
const filteredSessions = currentSessions.filter((session) =>
|
||||||
// (session) => new Date(session.expirationDate) > now
|
session.expirationDate ? new Date(session.expirationDate) > now : true
|
||||||
// );
|
);
|
||||||
// return setSessionHttpOnlyCookie(filteredSessions);
|
return setSessionHttpOnlyCookie(filteredSessions);
|
||||||
// } else {
|
} else {
|
||||||
return setSessionHttpOnlyCookie(currentSessions);
|
return setSessionHttpOnlyCookie(currentSessions);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateSessionCookie(
|
export async function updateSessionCookie(
|
||||||
@@ -72,15 +72,15 @@ export async function updateSessionCookie(
|
|||||||
|
|
||||||
if (foundIndex > -1) {
|
if (foundIndex > -1) {
|
||||||
sessions[foundIndex] = session;
|
sessions[foundIndex] = session;
|
||||||
// if (cleanup) {
|
if (cleanup) {
|
||||||
// const now = new Date();
|
const now = new Date();
|
||||||
// const filteredSessions = sessions.filter(
|
const filteredSessions = sessions.filter((session) =>
|
||||||
// (session) => new Date(session.expirationDate) > now
|
session.expirationDate ? new Date(session.expirationDate) > now : true
|
||||||
// );
|
);
|
||||||
// return setSessionHttpOnlyCookie(filteredSessions);
|
return setSessionHttpOnlyCookie(filteredSessions);
|
||||||
// } else {
|
} else {
|
||||||
return setSessionHttpOnlyCookie(sessions);
|
return setSessionHttpOnlyCookie(sessions);
|
||||||
// }
|
}
|
||||||
} else {
|
} else {
|
||||||
throw "updateSessionCookie: session id now found";
|
throw "updateSessionCookie: session id now found";
|
||||||
}
|
}
|
||||||
@@ -98,15 +98,15 @@ export async function removeSessionFromCookie(
|
|||||||
: [session];
|
: [session];
|
||||||
|
|
||||||
const reducedSessions = sessions.filter((s) => s.id !== session.id);
|
const reducedSessions = sessions.filter((s) => s.id !== session.id);
|
||||||
// if (cleanup) {
|
if (cleanup) {
|
||||||
// const now = new Date();
|
const now = new Date();
|
||||||
// const filteredSessions = reducedSessions.filter(
|
const filteredSessions = reducedSessions.filter((session) =>
|
||||||
// (session) => new Date(session.expirationDate) > now
|
session.expirationDate ? new Date(session.expirationDate) > now : true
|
||||||
// );
|
);
|
||||||
// return setSessionHttpOnlyCookie(filteredSessions);
|
return setSessionHttpOnlyCookie(filteredSessions);
|
||||||
// } else {
|
} else {
|
||||||
return setSessionHttpOnlyCookie(reducedSessions);
|
return setSessionHttpOnlyCookie(reducedSessions);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getMostRecentSessionCookie(): Promise<any> {
|
export async function getMostRecentSessionCookie(): Promise<any> {
|
||||||
@@ -192,14 +192,16 @@ export async function getAllSessionCookieIds(
|
|||||||
if (stringifiedCookie?.value) {
|
if (stringifiedCookie?.value) {
|
||||||
const sessions: SessionCookie[] = JSON.parse(stringifiedCookie?.value);
|
const sessions: SessionCookie[] = JSON.parse(stringifiedCookie?.value);
|
||||||
|
|
||||||
// if (cleanup) {
|
if (cleanup) {
|
||||||
// const now = new Date();
|
const now = new Date();
|
||||||
// return sessions
|
return sessions
|
||||||
// .filter((session) => new Date(session.expirationDate) > now)
|
.filter((session) =>
|
||||||
// .map((session) => session.id);
|
session.expirationDate ? new Date(session.expirationDate) > now : true
|
||||||
// } else {
|
)
|
||||||
return sessions.map((session) => session.id);
|
.map((session) => session.id);
|
||||||
// }
|
} else {
|
||||||
|
return sessions.map((session) => session.id);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -219,14 +221,14 @@ export async function getAllSessions(
|
|||||||
if (stringifiedCookie?.value) {
|
if (stringifiedCookie?.value) {
|
||||||
const sessions: SessionCookie[] = JSON.parse(stringifiedCookie?.value);
|
const sessions: SessionCookie[] = JSON.parse(stringifiedCookie?.value);
|
||||||
|
|
||||||
// if (cleanup) {
|
if (cleanup) {
|
||||||
// const now = new Date();
|
const now = new Date();
|
||||||
// return sessions.filter(
|
return sessions.filter((session) =>
|
||||||
// (session) => new Date(session.expirationDate) > now
|
session.expirationDate ? new Date(session.expirationDate) > now : true
|
||||||
// );
|
);
|
||||||
// } else {
|
} else {
|
||||||
return sessions;
|
return sessions;
|
||||||
// }
|
}
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user