(username: string)
| 24 | * Create a signed session token for local auth. |
| 25 | */ |
| 26 | export function createSessionToken(username: string): string { |
| 27 | const secret = getSessionSecret(); |
| 28 | const payload = JSON.stringify({ username, ts: Date.now() }); |
| 29 | const hmac = crypto.createHmac('sha256', secret); |
| 30 | hmac.update(payload); |
| 31 | const signature = hmac.digest('hex'); |
| 32 | return Buffer.from(`${payload}.${signature}`).toString('base64'); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Verify and decode a session token. |
no test coverage detected