feat: copy full API key on-demand di halaman dev
Sebelumnya copy button mengcopy key yang sudah ter-mask dari list endpoint Desa+ API. Sekarang klik copy fetch full key via GET /api-keys/:id lalu salin ke clipboard.
This commit is contained in:
13
src/app.ts
13
src/app.ts
@@ -1688,6 +1688,19 @@ export function createApp() {
|
||||
return { keys: json.data ?? [] }
|
||||
})
|
||||
|
||||
.get('/api/admin/api-keys/:id', async ({ request, set, params }) => {
|
||||
const auth = await requireDeveloper(request, set)
|
||||
if (!auth) return { error: set.status === 401 ? 'Unauthorized' : 'Forbidden' }
|
||||
const app = await prisma.app.findUnique({ where: { id: 'desa-plus' } })
|
||||
if (!app?.urlApi) { set.status = 503; return { error: 'desa-plus belum dikonfigurasi' } }
|
||||
const res = await fetch(`${app.urlApi.replace(/\/$/, '')}/api/monitoring/api-keys/${params.id}`, {
|
||||
headers: { 'x-api-key': app.apiKey ?? '' },
|
||||
})
|
||||
const json = await res.json()
|
||||
set.status = res.status
|
||||
return json
|
||||
})
|
||||
|
||||
.post('/api/admin/api-keys', async ({ request, set }) => {
|
||||
const auth = await requireDeveloper(request, set)
|
||||
if (!auth) return { error: set.status === 401 ? 'Unauthorized' : 'Forbidden' }
|
||||
|
||||
Reference in New Issue
Block a user