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

6
mod.ts
View File

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