Skip to content

Commit bf53d39

Browse files
committed
dev-demo: add button to text 2fa.verifyAuto method
1 parent 6bb1bc8 commit bf53d39

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

dev-demo/api.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Express, Response } from "express";
22
import { IAdminForth, IAdminUserExpressRequest } from "adminforth";
33
import * as z from "zod";
4+
import TwoFactorsAuthPlugin from "../plugins/adminforth-two-factors-auth/index.js";
45

56
const DASHBOARD_CAR_SOURCES = [
67
{ resourceId: 'cars_sl', label: 'SQLite' },
@@ -172,4 +173,15 @@ export function initApi(app: Express, admin: IAdminForth) {
172173
)
173174
)
174175
);
176+
app.get(`${admin.config.baseUrl}/api/test2faCall/`,
177+
admin.express.authorize(
178+
async (_req: IAdminUserExpressRequest, res: Response) => {
179+
console.log('Received test2faCall');
180+
const { adminUser } = _req;
181+
const t2fa = admin.getPluginByClassName<TwoFactorsAuthPlugin>('TwoFactorsAuthPlugin');
182+
const verifyResult = await t2fa.verifyAuto(adminUser);
183+
res.json({ message: "2FA call received!" });
184+
}
185+
)
186+
);
175187
}

dev-demo/custom/AfComponents.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@
389389
Refresh badge
390390
</Button>
391391

392+
<Button @click="doTest2faCall">
393+
Test 2FA API Call
394+
</Button>
392395
</div>
393396

394397

@@ -543,4 +546,12 @@ async function callHelloWorldApi() {
543546
console.error('API error:', error);
544547
}
545548
}
549+
550+
async function doTest2faCall() {
551+
try {
552+
const response = await callApi({ path: '/api/test2faCall/', method: 'GET' });
553+
} catch (error) {
554+
console.error('2FA API error:', error);
555+
}
556+
}
546557
</script>

0 commit comments

Comments
 (0)