|
1 | | -import { env } from "bun"; |
2 | | -import jwt from "jsonwebtoken"; |
3 | | -import { z } from "@hono/zod-openapi"; |
| 1 | +import { env } from 'bun'; |
| 2 | +import jwt from 'jsonwebtoken'; |
| 3 | +import { z } from '@hono/zod-openapi'; |
4 | 4 |
|
5 | 5 | export const JwtAuthResponses = { |
6 | | - 401: { |
7 | | - content: { |
8 | | - "application/json": { |
9 | | - schema: z.object({ error: z.string() }), |
10 | | - }, |
| 6 | + 401: { |
| 7 | + content: { |
| 8 | + 'application/json': { |
| 9 | + schema: z.object({ error: z.string() }), |
| 10 | + }, |
| 11 | + }, |
| 12 | + description: 'The JWT token is missing or is invalid.', |
11 | 13 | }, |
12 | | - description: "The JWT token is missing or is invalid.", |
13 | | - }, |
14 | 14 | }; |
15 | 15 |
|
16 | 16 | export interface AuthJwtPayload { |
17 | | - sandboxId?: string; |
18 | | - userId?: string; |
| 17 | + sandboxId?: string; |
| 18 | + userId?: string; |
19 | 19 | } |
20 | 20 |
|
21 | 21 | export function encodeJwtToken(jwtPayload: AuthJwtPayload) { |
22 | | - return jwt.sign(jwtPayload, env.JWT_SECRET_KEY!, { |
23 | | - expiresIn: "1d", |
24 | | - }); |
| 22 | + return jwt.sign(jwtPayload, env.JWT_SECRET_KEY!, { |
| 23 | + expiresIn: '1d', |
| 24 | + }); |
25 | 25 | } |
26 | 26 |
|
27 | 27 | export function decodeJwtToken(token: string) { |
28 | | - return jwt.verify(token, env.JWT_SECRET_KEY!); |
| 28 | + return jwt.verify(token, env.JWT_SECRET_KEY!); |
29 | 29 | } |
30 | 30 |
|
31 | 31 | export function verifyApiKeyFromHeader(header?: string) { |
32 | | - const apiKey = header?.toLowerCase().split("bearer ")[1]; |
33 | | - if (!apiKey) { |
34 | | - return false; |
35 | | - } |
36 | | - return verifyApiKey(apiKey); |
| 32 | + const apiKey = header?.toLowerCase().split('bearer ')[1]; |
| 33 | + if (!apiKey) { |
| 34 | + return false; |
| 35 | + } |
| 36 | + return verifyApiKey(apiKey); |
37 | 37 | } |
38 | 38 |
|
39 | 39 | export function verifyApiKey(apiKey: string) { |
40 | | - return apiKey === env.SUPAROUTA_API_KEY; |
| 40 | + return apiKey === env.CODEROUTER_API_KEY; |
41 | 41 | } |
0 commit comments