(value: string, req: Request, res: Response, maxAge: number = 0)
| 12 | } |
| 13 | |
| 14 | setValue(value: string, req: Request, res: Response, maxAge: number = 0) { |
| 15 | const opts: { |
| 16 | httpOnly: boolean; |
| 17 | maxAge: number; |
| 18 | secure: boolean; |
| 19 | path?: string; |
| 20 | } = { |
| 21 | httpOnly: true, |
| 22 | maxAge: maxAge || this.expires, |
| 23 | secure: req.secure, |
| 24 | }; |
| 25 | if (this.path) { |
| 26 | opts.path = this.path; |
| 27 | } |
| 28 | |
| 29 | if (!value) { |
| 30 | res.clearCookie(this.key, opts); |
| 31 | } else { |
| 32 | res.cookie(this.key, value, opts); |
| 33 | } |
| 34 | |
| 35 | // Clear any legacy cookie at the default path during transition |
| 36 | if (this.path) { |
| 37 | res.clearCookie(this.key, { |
| 38 | httpOnly: true, |
| 39 | secure: req.secure, |
| 40 | }); |
| 41 | } |
| 42 | |
| 43 | req.cookies[this.key] = value; |
| 44 | } |
| 45 | |
| 46 | getValue(req: Request) { |
| 47 | return req.cookies[this.key] || ""; |
no test coverage detected