feat: Add API key support
This commit is contained in:
19
src/pages/api/users/[userId]/keys/index.ts
Normal file
19
src/pages/api/users/[userId]/keys/index.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import type { APIRoute } from 'astro'
|
||||
import crypto from 'node:crypto'
|
||||
import DaoFactory from '../../../../../models/DaoFactory'
|
||||
|
||||
export const post: APIRoute = async ({ params, request }) => {
|
||||
const userId = params.userId as string
|
||||
|
||||
const dao = await DaoFactory.get('apiKey').create({
|
||||
user: userId,
|
||||
key: crypto.randomUUID(),
|
||||
permissions: [
|
||||
'admin.user.list'
|
||||
]
|
||||
})
|
||||
return {
|
||||
status: 201,
|
||||
body: JSON.stringify(dao)
|
||||
}
|
||||
}
|
17
src/pages/api/users/index.ts
Normal file
17
src/pages/api/users/index.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import type { APIRoute } from 'astro'
|
||||
import { validateAuth } from '../../../libs/validateAuth'
|
||||
|
||||
export const get: APIRoute = async ({ params, request }) => {
|
||||
const requestInvalid = await validateAuth(request, {
|
||||
name: 'user.list',
|
||||
api: false,
|
||||
cookie: true
|
||||
})
|
||||
if (requestInvalid) {
|
||||
return requestInvalid
|
||||
}
|
||||
return {
|
||||
status: 200,
|
||||
body: JSON.stringify({iam: true})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user