diff --git a/adminforth/documentation/docs/tutorial/07-Plugins/02-TwoFactorsAuth.md b/adminforth/documentation/docs/tutorial/07-Plugins/02-TwoFactorsAuth.md index 60eaf082..869a7bba 100644 --- a/adminforth/documentation/docs/tutorial/07-Plugins/02-TwoFactorsAuth.md +++ b/adminforth/documentation/docs/tutorial/07-Plugins/02-TwoFactorsAuth.md @@ -205,4 +205,127 @@ plugins: [ }), ], ... -``` \ No newline at end of file +``` + +## Request 2FA on custom Actions + +You might want to to allow to call some custom critical/money related actions with additional 2FA approval. This eliminates risk that user cookies might be stolen by some virous/doorway software after login. + +To do it you first need to create custom component which will call `window.adminforthTwoFaModal.getCode(cb?)` frontend API exposed by this plugin. This is awaitable call wich shows 2FA popup and asks user to enter a code. + +```ts title='/custom/RequireTwoFaGate.vue' + + + +``` + +Now we need to read code entered on fronted on backend and verify that is is valid and not expired, on backend action handler: + +```ts title='/adminuser.ts' +options: { + actions: [ + { + name: 'Auto submit', + icon: 'flowbite:play-solid', + allowed: () => true, + action: async ({ recordId, adminUser, payload, adminforth }) => { + const { code } = payload; + const totpIsValid = adminforth.getPluginByClassName<>('T2FAPlug').verify(code); + if (!totpIsValid) { + return { ok: false, error: 'TOTP code is invalid' } + } + // we will also register fact of ussage of this critical action using audit log Plugin + getPluginBYClassName.logCustomAction()... + .... your critical action logic .... + return { ok: true, successMessage: 'Auto submitted' } + }, + showIn: { showButton: true, showThreeDotsMenu: true, list: true }, + //diff-add + customComponent: '@@/RequireTwoFaGate.vue', + }, + ], +} +``` + +## Request 2FA from custom components + +Imagine you have some button which does some API call + +```ts + + + + \ No newline at end of file diff --git a/adminforth/spa/src/components/ResourceListTable.vue b/adminforth/spa/src/components/ResourceListTable.vue index 0bde9373..7810949d 100644 --- a/adminforth/spa/src/components/ResourceListTable.vue +++ b/adminforth/spa/src/components/ResourceListTable.vue @@ -176,13 +176,36 @@