({
passwordFromArgs = "",
cookieKey,
hashedPasswordFromArgs = "",
passwordMethod,
}: IsCookieValidArgs)
| 270 | |
| 271 | /** Checks if a req.cookies.key is valid using the PasswordMethod */ |
| 272 | export async function isCookieValid({ |
| 273 | passwordFromArgs = "", |
| 274 | cookieKey, |
| 275 | hashedPasswordFromArgs = "", |
| 276 | passwordMethod, |
| 277 | }: IsCookieValidArgs): Promise<boolean> { |
| 278 | let isValid = false |
| 279 | switch (passwordMethod) { |
| 280 | case "PLAIN_TEXT": |
| 281 | isValid = await isHashMatch(passwordFromArgs, cookieKey) |
| 282 | break |
| 283 | case "ARGON2": |
| 284 | case "SHA256": |
| 285 | isValid = safeCompare(cookieKey, hashedPasswordFromArgs) |
| 286 | break |
| 287 | default: |
| 288 | break |
| 289 | } |
| 290 | return isValid |
| 291 | } |
| 292 | |
| 293 | /** Ensures that the input is sanitized by checking |
| 294 | * - it's a string |
no test coverage detected