allow undefined arg for cookie, just set cookie if session has entries
This commit is contained in:
parent
96a73035f8
commit
8a3683d2e5
20
mod.ts
20
mod.ts
|
@ -278,13 +278,17 @@ export class HTTPServer {
|
|||
private processSession(routeRequest: RouteRequest, routeReply: RouteReply) {
|
||||
if (this.settings?.sessionSecret) {
|
||||
const sessionObject = JSON.stringify(routeRequest.session);
|
||||
const encodedSession = encryptData(
|
||||
sessionObject,
|
||||
this.settings?.sessionSecret,
|
||||
);
|
||||
routeReply.cookie("session", encodedSession, {
|
||||
maxAge: this.settings.sessionExpire ?? undefined,
|
||||
});
|
||||
if (Object.keys(routeRequest.session).length > 0) {
|
||||
const encodedSession = encryptData(
|
||||
sessionObject,
|
||||
this.settings?.sessionSecret,
|
||||
);
|
||||
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;
|
||||
|
|
Reference in New Issue
Block a user