File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { Express , Response } from "express" ;
22import { IAdminForth , IAdminUserExpressRequest } from "adminforth" ;
33import * as z from "zod" ;
4+ import TwoFactorsAuthPlugin from "../plugins/adminforth-two-factors-auth/index.js" ;
45
56const 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}
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments