api-keys.ts50 lines · main
| 1 | import { components } from 'api-types' |
| 2 | import { NextApiRequest, NextApiResponse } from 'next' |
| 3 | |
| 4 | import apiWrapper from '@/lib/api/apiWrapper' |
| 5 | |
| 6 | type ProjectAppConfig = components['schemas']['ProjectSettingsResponse']['app_config'] & { |
| 7 | protocol?: string |
| 8 | } |
| 9 | export type ProjectSettings = components['schemas']['ProjectSettingsResponse'] & { |
| 10 | app_config?: ProjectAppConfig |
| 11 | } |
| 12 | |
| 13 | export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler) |
| 14 | |
| 15 | async function handler(req: NextApiRequest, res: NextApiResponse) { |
| 16 | const { method } = req |
| 17 | |
| 18 | switch (method) { |
| 19 | case 'GET': |
| 20 | return handleGetAll(req, res) |
| 21 | default: |
| 22 | res.setHeader('Allow', ['GET']) |
| 23 | res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } }) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | const handleGetAll = async (_req: NextApiRequest, res: NextApiResponse) => { |
| 28 | const response = [ |
| 29 | { |
| 30 | name: 'anon', |
| 31 | api_key: process.env.BRIVEN_ANON_KEY ?? '', |
| 32 | id: 'anon', |
| 33 | type: 'legacy', |
| 34 | hash: '', |
| 35 | prefix: '', |
| 36 | description: 'Legacy anon API key', |
| 37 | }, |
| 38 | { |
| 39 | name: 'service_role', |
| 40 | api_key: process.env.BRIVEN_SERVICE_KEY ?? '', |
| 41 | id: 'service_role', |
| 42 | type: 'legacy', |
| 43 | hash: '', |
| 44 | prefix: '', |
| 45 | description: 'Legacy service_role API key', |
| 46 | }, |
| 47 | ] |
| 48 | |
| 49 | return res.status(200).json(response) |
| 50 | } |