(options: CookieOptions)
| 154 | * Create secure cookie string with all options |
| 155 | */ |
| 156 | export function createSecureCookie(options: CookieOptions): string { |
| 157 | const { |
| 158 | name, |
| 159 | value, |
| 160 | maxAge = 7 * 24 * 60 * 60, // 7 days default |
| 161 | secure = true, |
| 162 | sameSite = 'Lax', |
| 163 | path = '/', |
| 164 | domain, |
| 165 | } = options; |
| 166 | |
| 167 | const parts = [`${name}=${encodeURIComponent(value)}`]; |
| 168 | |
| 169 | if (maxAge > 0) parts.push(`Max-Age=${maxAge}`); |
| 170 | if (path) parts.push(`Path=${path}`); |
| 171 | if (domain) parts.push(`Domain=${domain}`); |
| 172 | if (secure) parts.push('Secure'); |
| 173 | if (sameSite) parts.push(`SameSite=${sameSite}`); |
| 174 | |
| 175 | parts.push('HttpOnly'); |
| 176 | |
| 177 | return parts.join('; '); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Set auth cookies with proper security settings |
no test coverage detected