(secret: string, token: string)
| 25 | * Verifies a token and returns the payload if valid. |
| 26 | */ |
| 27 | export async function verifyDurableIteratorToken(secret: string, token: string): Promise<DurableIteratorTokenPayload | undefined> { |
| 28 | try { |
| 29 | const payload = parseEmptyableJSON(await unsign(token, secret)) |
| 30 | |
| 31 | if (!v.is(DurableIteratorTokenPayloadSchema, payload)) { |
| 32 | return undefined |
| 33 | } |
| 34 | |
| 35 | if (payload.exp < (Date.now() / 1000)) { |
| 36 | return undefined |
| 37 | } |
| 38 | |
| 39 | return payload |
| 40 | } |
| 41 | catch { |
| 42 | // parseEmptyableJSON can throw error if the token contains invalid json |
| 43 | return undefined |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Extracts the payload from a token without verifying its signature. |
no test coverage detected