(request: Request)
| 140 | } |
| 141 | |
| 142 | export function readSessionCookie(request: Request): string | null { |
| 143 | const header = request.headers.get('cookie'); |
| 144 | if (!header) return null; |
| 145 | for (const part of header.split(';')) { |
| 146 | const cookie = part.trim(); |
| 147 | if (cookie.startsWith(`${COOKIE_NAME}=`)) return cookie.slice(COOKIE_NAME.length + 1); |
| 148 | } |
| 149 | return null; |
| 150 | } |
| 151 | |
| 152 | export function sessionCookie(token: string): string { |
| 153 | // Secure is accepted on http://localhost too, so `wrangler dev` still works. |