diff --git a/adminforth/commands/createApp/templates/api.ts.hbs b/adminforth/commands/createApp/templates/api.ts.hbs index 6aac70a5..c9fef34b 100644 --- a/adminforth/commands/createApp/templates/api.ts.hbs +++ b/adminforth/commands/createApp/templates/api.ts.hbs @@ -2,6 +2,11 @@ import { Express, Request, Response } from "express"; import { IAdminForth } from "adminforth"; export function initApi(app: Express, admin: IAdminForth) { app.get(`${admin.config.baseUrl}/api/hello/`, + + // you can use data API to work with your database https://adminforth.dev/docs/tutorial/Customization/dataApi/ + const allUsers = await admin.resource.list([]); + + // you can use req.adminUser to get info about the logged-in admin user async (req: Request, res: Response) => { const allUsers = await admin.resource("adminuser").list([]); res.json({ @@ -9,5 +14,12 @@ export function initApi(app: Express, admin: IAdminForth) { users: allUsers, }); } + + // you can use admin.express.authorize to get info about the current user + admin.express.authorize( + async (req: Request, res: Response) => { + res.json({ message: "Hello from AdminForth API!", adminUser: req.adminUser }); + } + ) ); } \ No newline at end of file