Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions adminforth/commands/createApp/templates/api.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ 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([]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you getting the same users twice?


// 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({
message: "Hello from AdminForth API!",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better will be to change this message to something like "List of my users from AdminForth API"

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 });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

}
)
);
}