Skip to content

Commit b43133a

Browse files
committed
docs: update docs for the 2fa plugin
1 parent 09040ed commit b43133a

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

adminforth/documentation/docs/tutorial/07-Plugins/02-TwoFactorsAuth.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ Then:
4242
4343
```bash
4444
npm run makemigration -- --name add-2fa-secret ; npm run migrate:local
45-
46-
4745
```
4846
4947
And add it to `adminuser.ts`
@@ -265,7 +263,7 @@ options: {
265263
name: 'Auto submit',
266264
icon: 'flowbite:play-solid',
267265
allowed: () => true,
268-
action: async ({ recordId, adminUser, adminforth, extra }) => {
266+
action: async ({ recordId, adminUser, adminforth, response, extra }) => {
269267
//diff-add
270268
const verificationResult = extra?.verificationResult
271269
//diff-add
@@ -283,7 +281,11 @@ options: {
283281
//diff-add
284282
userPk: adminUser.pk,
285283
//diff-add
286-
cookies: extra.cookies
284+
cookies: extra.cookies,
285+
//diff-add
286+
response: response,
287+
//diff-add
288+
extra: extra,
287289
//diff-add
288290
});
289291

@@ -332,7 +334,7 @@ To protect create and edit operations, collect the result of the 2FA modal on th
332334
333335
Frontend (custom Save button example):
334336
335-
```vue
337+
```ts
336338
<template>
337339
<button :disabled="disabled || saving || !isValid" @click="onClick">Save</button>
338340
<!-- The plugin injects TwoFAModal globally, exposing window.adminforthTwoFaModal -->
@@ -369,7 +371,7 @@ Backend (resource hook verification):
369371
// Inside resource config
370372
hooks: {
371373
edit: {
372-
beforeSave: async ({ adminUser, adminforth, extra }) => {
374+
beforeSave: async ({ adminUser, adminforth, response, extra }) => {
373375
const t2fa = adminforth.getPluginByClassName('TwoFactorsAuthPlugin');
374376
const confirmationResult = extra?.body?.meta?.confirmationResult;
375377
if (!confirmationResult) {
@@ -380,6 +382,8 @@ hooks: {
380382
adminUser,
381383
userPk: adminUser.pk,
382384
cookies,
385+
response,
386+
extra
383387
});
384388
if (!('ok' in verifyRes) || verifyRes.ok !== true) {
385389
return { ok: false, error: verifyRes?.error || 'Two-factor authentication failed' };
@@ -495,8 +499,12 @@ app.post(`${ADMIN_BASE_URL}/myCriticalAction`,
495499
// diff-add
496500
userPk: adminUser.pk,
497501
// diff-add
498-
cookies: cookies
499-
// diff-add
502+
cookies: cookies,
503+
//diff-add
504+
response: res,
505+
//diff-add
506+
extra: {...req.headers},
507+
//diff-add
500508
});
501509
// diff-add
502510
if (!('ok' in verifyRes)) {
@@ -531,8 +539,6 @@ app.post(`${ADMIN_BASE_URL}/myCriticalAction`,
531539
532540
### Step-Up Authentication Grace Period
533541
534-
> 💡** Note ** this feature is now in development and might be not yet available.
535-
536542
By default, step-up authentication is required every time the user performs a critical operation.
537543
538544
While it might be nessesary for high-security applications, it can be inconvenient for users who perform multiple critical actions in a short period. To fix the issue (by lowering security a bit), you can enable grace period between step-up authentication requests:

0 commit comments

Comments
 (0)