Download cloud-v2/packages/runtime/src/api/runtime-auth.ts from Anirudh1950/MentraOS: direct link, hf CLI and curl.
- Browser
- Download file 782 Bytes
-
https://huggingface.co/Anirudh1950/MentraOS/resolve/main/cloud-v2/packages/runtime/src/api/runtime-auth.ts
- Command line
-
hf download hf://Anirudh1950/MentraOS/cloud-v2/packages/runtime/src/api/runtime-auth.ts
-
curl -L -o runtime-auth.ts https://huggingface.co/Anirudh1950/MentraOS/resolve/main/cloud-v2/packages/runtime/src/api/runtime-auth.ts
782 Bytes
| import type { Context } from "hono"; | |
| import { | |
| AccessTokenError, | |
| verifyRuntimeToken, | |
| type VerifiedAccessToken, | |
| } from "@mentra/cloud-shared"; | |
| export async function authenticateRuntimeRequest( | |
| c: Context, | |
| ): Promise<{ identity: VerifiedAccessToken } | { error: Response }> { | |
| const authHeader = c.req.header("authorization"); | |
| const match = authHeader?.match(/^Bearer\s+(.+)$/i); | |
| const token = match?.[1]?.trim(); | |
| if (!token) { | |
| return { | |
| error: c.json({ error: "missing or malformed Authorization" }, 401), | |
| }; | |
| } | |
| try { | |
| return { identity: await verifyRuntimeToken(token) }; | |
| } catch (err) { | |
| if (err instanceof AccessTokenError) { | |
| return { error: c.json({ error: err.message }, 401) }; | |
| } | |
| throw err; | |
| } | |
| } | |