Create a per-user admin page to inspect users
Add page to allow admins to inspect all of the details stored on the server of a user account. For now this is just the UserDetails, but in the future this is planned to be expanded to also show sessions and logs.
This commit is contained in:
parent
52973ffa9a
commit
d006be251c
7 changed files with 176 additions and 26 deletions
34
server/api/users/[id]/details.get.ts
Normal file
34
server/api/users/[id]/details.get.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { z } from "zod/v4-mini";
|
||||
import { readUsers } from "~/server/database";
|
||||
import { serverUserToApiDetails } from "~/server/utils/user";
|
||||
|
||||
const integerStringSchema = z.pipe(
|
||||
z.string().check(z.regex(/^\d+/)),
|
||||
z.transform(Number)
|
||||
);
|
||||
|
||||
const detailsSchema = z.object({
|
||||
id: integerStringSchema,
|
||||
});
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await requireServerSessionWithAdmin(event);
|
||||
const users = await readUsers();
|
||||
const { success, error, data: params } = detailsSchema.safeParse(getRouterParams(event));
|
||||
if (!success) {
|
||||
throw createError({
|
||||
status: 400,
|
||||
statusText: "Bad Request",
|
||||
message: z.prettifyError(error),
|
||||
});
|
||||
}
|
||||
const user = users.find(user => user.id === params.id);
|
||||
if (!user) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: "Not found",
|
||||
});
|
||||
}
|
||||
|
||||
return serverUserToApiDetails(user);
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue