allow undefined arg for cookie, just set cookie if session has entries

This commit is contained in:
HorizonCode 2023-05-13 06:29:01 +02:00
parent 96a73035f8
commit 8a3683d2e5

20
mod.ts
View File

@ -278,13 +278,17 @@ export class HTTPServer {
private processSession(routeRequest: RouteRequest, routeReply: RouteReply) { private processSession(routeRequest: RouteRequest, routeReply: RouteReply) {
if (this.settings?.sessionSecret) { if (this.settings?.sessionSecret) {
const sessionObject = JSON.stringify(routeRequest.session); const sessionObject = JSON.stringify(routeRequest.session);
const encodedSession = encryptData( if (Object.keys(routeRequest.session).length > 0) {
sessionObject, const encodedSession = encryptData(
this.settings?.sessionSecret, sessionObject,
); this.settings?.sessionSecret,
routeReply.cookie("session", encodedSession, { );
maxAge: this.settings.sessionExpire ?? undefined, routeReply.cookie("session", encodedSession, {
}); maxAge: this.settings.sessionExpire ?? undefined,
});
}else{
routeReply.cookie("session", undefined);
}
} }
} }
@ -503,7 +507,7 @@ export class RouteReply {
return this; return this;
} }
cookie(name: string, value: string, attributes?: { cookie(name: string, value: string | undefined, attributes?: {
expires?: Date | number; expires?: Date | number;
maxAge?: number; maxAge?: number;
domain?: string; domain?: string;