Skip to content

Commit 4af7719

Browse files
authored
Merge pull request #517 from devforth/feature/AdminForth/1210/please-extend-cle-generate-api
feat: extend API to include all user and current user in response
2 parents f107720 + 911af8b commit 4af7719

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

adminforth/commands/createApp/templates/api.ts.hbs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@ import { Express, Request, Response } from "express";
22
import { IAdminForth } from "adminforth";
33
export function initApi(app: Express, admin: IAdminForth) {
44
app.get(`${admin.config.baseUrl}/api/hello/`,
5+
6+
// you can use data API to work with your database https://adminforth.dev/docs/tutorial/Customization/dataApi/
57
async (req: Request, res: Response) => {
8+
// req.adminUser to get info about the admin users
69
const allUsers = await admin.resource("adminuser").list([]);
710
res.json({
8-
message: "Hello from AdminForth API!",
11+
message: "List of admin users from AdminForth API",
912
users: allUsers,
1013
});
1114
}
15+
16+
// you can use admin.express.authorize to get info about the current user
17+
admin.express.authorize(
18+
async (req: Request, res: Response) => {
19+
res.json({ message: "Current adminuser from AdminForth API", adminUser: req.adminUser });
20+
}
21+
)
1222
);
1323
}

0 commit comments

Comments
 (0)