@@ -343,11 +343,13 @@ registerSaveInterceptor(async ({ action, values, resource }) => {
343343 const modal = (window as any )?.adminforthTwoFaModal ;
344344 if (modal ?.get2FaConfirmationResult ) {
345345 const confirmationResult = await modal .get2FaConfirmationResult (undefined , ' Confirm to save changes' );
346- if (! confirmationResult ) return { ok: false , error: ' 2FA cancelled' };
346+ if (! confirmationResult ) {
347+ return { ok: false , error: ' Two-factor authentication cancelled' };
348+ }
347349 // Pass data to backend; the view will forward extra.confirmationResult to meta.confirmationResult
348350 return { ok: true , extra: { confirmationResult } };
349351 }
350- return { ok: false , error: ' 2FA code is required' };
352+ return { ok: false , error: ' Two-factor authentication code is required' };
351353});
352354< / script >
353355
@@ -364,7 +366,7 @@ options: {
364366 }
365367}
366368` ` `
367- > Note: You can use all injection , not only bottom
369+ > Note: You can use all injections , not only bottom
368370
369371Backend (resource hook verification):
370372
@@ -374,27 +376,34 @@ hooks: {
374376 edit: {
375377 beforeSave : async ({ adminUser , adminforth , extra }) => {
376378 const t2fa = adminforth .getPluginByClassName (' TwoFactorsAuthPlugin' );
377- const confirmationResult = extra ?.body ?.meta ?.confirmationResult ;
379+ if (! t2fa ) {
380+ return { ok: false , error: ' TwoFactorsAuthPlugin is not configured' };
381+ }
378382
383+ const confirmationResult = extra ?.body ?.meta ?.confirmationResult ;
379384 if (! confirmationResult ) {
380385 return { ok: false , error: ' Two-factor authentication confirmation result is missing' };
381386 }
387+
382388 const verifyRes = await t2fa .verify (confirmationResult , {
383389 adminUser ,
384390 userPk: adminUser .pk ,
385391 cookies: extra ?.cookies ,
386392 });
387393 if (! verifyRes || ' error' in verifyRes ) {
388- return { ok: false , error: verifyRes ?.error || ' 2FA verification failed' };
394+ return { ok: false , error: verifyRes ?.error || ' Two-factor verification failed' };
389395 }
390396 return { ok: true };
391397 },
392398 },
393399 create: {
394400 beforeSave : async ({ adminUser , adminforth , extra }) => {
395401 const t2fa = adminforth .getPluginByClassName (' TwoFactorsAuthPlugin' );
396- const confirmationResult = extra ?.body ?.meta ?.confirmationResult ;
402+ if (! t2fa ) {
403+ return { ok: false , error: ' TwoFactorsAuthPlugin is not configured' };
404+ }
397405
406+ const confirmationResult = extra ?.body ?.meta ?.confirmationResult ;
398407 if (! confirmationResult ) {
399408 return { ok: false , error: ' Two-factor authentication confirmation result is missing' };
400409 }
@@ -405,7 +414,7 @@ hooks: {
405414 cookies: extra ?.cookies ,
406415 });
407416 if (! verifyRes || ' error' in verifyRes ) {
408- return { ok: false , error: verifyRes ?.error || ' 2FA verification failed' };
417+ return { ok: false , error: verifyRes ?.error || ' Two-factor verification failed' };
409418 }
410419 return { ok: true };
411420 },
0 commit comments