fix client error

This commit is contained in:
Max Peintner
2023-06-30 14:13:03 +02:00
parent f324407a83
commit 9ba466387b
21 changed files with 140 additions and 120 deletions

View File

@@ -55,9 +55,12 @@ export async function updateSessionCookie(
: [session];
const foundIndex = sessions.findIndex((session) => session.id === id);
sessions[foundIndex] = session;
return setSessionHttpOnlyCookie(sessions);
if (foundIndex > -1) {
sessions[foundIndex] = session;
return setSessionHttpOnlyCookie(sessions);
} else {
throw "updateSessionCookie: session id now found";
}
}
export async function removeSessionFromCookie(
@@ -119,11 +122,9 @@ export async function getSessionCookieByLoginName(
const cookiesList = cookies();
const stringifiedCookie = cookiesList.get("sessions");
console.log("str", stringifiedCookie);
if (stringifiedCookie?.value) {
const sessions: SessionCookie[] = JSON.parse(stringifiedCookie?.value);
console.log("sessions", sessions);
const found = sessions.find((s) => s.loginName === loginName);
if (found) {
return found;

View File

@@ -86,13 +86,9 @@ export async function setSessionAndUpdateCookie(
loginName: session.factors?.user?.loginName ?? "",
};
return updateSessionCookie(sessionCookie.id, newCookie)
.then(() => {
return session;
})
.catch((error) => {
throw "could not set cookie";
});
return updateSessionCookie(sessionCookie.id, newCookie).then(() => {
return session;
});
} else {
throw "could not get session or session does not have loginName";
}