Skip to content

Commit b985796

Browse files
committed
feat: extend API to include all user and current user in response
1 parent 08ea8e3 commit b985796

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,24 @@ 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/
7+
const allUsers = await admin.resource.list([]);
8+
9+
// you can use req.adminUser to get info about the logged-in admin user
510
async (req: Request, res: Response) => {
611
const allUsers = await admin.resource("adminuser").list([]);
712
res.json({
813
message: "Hello from AdminForth API!",
914
users: allUsers,
1015
});
1116
}
17+
18+
// you can use admin.express.authorize to get info about the current user
19+
admin.express.authorize(
20+
async (req: Request, res: Response) => {
21+
res.json({ message: "Hello from AdminForth API!", adminUser: req.adminUser });
22+
}
23+
)
1224
);
1325
}

0 commit comments

Comments
 (0)