mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-08-04 12:33:56 +08:00
Adding a very rudimentary admin page that displays a table of users and their basic information
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import client from "src/lib/prismadb";
|
||||
|
||||
/**
|
||||
* Returns a list of user results from the database when the requesting user is
|
||||
* a logged in admin.
|
||||
*/
|
||||
const handler = async (req, res) => {
|
||||
const token = await getToken({ req });
|
||||
|
||||
// Return nothing if the user isn't registered or if the user isn't an admin.
|
||||
if (!token || token.role !== "admin") {
|
||||
res.status(403).end();
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch 20 users.
|
||||
const users = await client.user.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
role: true,
|
||||
name: true,
|
||||
email: true,
|
||||
},
|
||||
take: 20,
|
||||
});
|
||||
|
||||
res.status(200).json(users);
|
||||
};
|
||||
|
||||
export default handler;
|
||||
Reference in New Issue
Block a user