| 1 | import { timingSafeEqual } from "crypto"; |
| 2 | import type { NextRequest |
| 3 | import { db } |
| 4 | import { nodes } |
| 5 | import { eq } |
| 6 | import { safeDecrypt } |
| 7 | |
| 8 | type NodeRecord |
| 9 | |
| 10 | export type WingsAuthResult |
| 11 | | { ok |
| 12 | | { ok |
| 13 | |
| 14 | export async function authenticateWings |
| 15 | req: NextRequest |
| 16 | ): Promise<WingsAuthResult |
| 17 | const authHeader = |
| 18 | if (!authHeader.startsWith |
| 19 | return { ok: |
| 20 | } |
| 21 | |
| 22 | const bearer = |
| 23 | const dotIdx = |
| 24 | if (dotIdx === |
| 25 | return { ok: |
| 26 | } |
| 27 | |
| 28 | const tokenId = |
| 29 | const token = |
| 30 | |
| 31 | const node = |
| 32 | where: eq(nodes |
| 33 | }); |
| 34 | |
| 35 | if (!node) |
| 36 | return { ok: |
| 37 | } |
| 38 | |
| 39 | try { |
| 40 | const a = |
| 41 | const b = |
| 42 | if (a.length |
| 43 | return { |
| 44 | ok: false, |
| 45 | response: new Response |
| 46 | }; |
| 47 | } |
| 48 | } catch { |
| 49 | return { ok: |
| 50 | } |
| 51 | |
| 52 | return { ok: |
| 53 | } |