Skip to content

Commit ca4597a

Browse files
committed
docs: update docs for the Two-Factor Authentication plugin
1 parent 598b840 commit ca4597a

File tree

4 files changed

+145
-1
lines changed

4 files changed

+145
-1
lines changed

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

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,148 @@ plugins: [
205205
}),
206206
],
207207
...
208-
```
208+
```
209+
210+
## Passkeys setup
211+
212+
If you want to use both passkeys and TOTP simultaneously, you can set them up as follows:
213+
214+
First, you need to create a passkeys table in your schema.prisma file:
215+
216+
```ts title='./schema.prisma'
217+
//diff-add
218+
model passkeys {
219+
//diff-add
220+
credential_id String @id
221+
//diff-add
222+
user_id String
223+
//diff-add
224+
meta String
225+
//diff-add
226+
@@index([user_id])
227+
//diff-add
228+
}
229+
```
230+
231+
Next, you need to create a new resource for passkeys:
232+
233+
```ts title='./resources/passkeys.ts'
234+
import { AdminForthDataTypes, AdminForthResourceInput } from "../../adminforth";
235+
236+
export default {
237+
dataSource: 'maindb',
238+
table: 'passkeys',
239+
resourceId: 'passkeys',
240+
label: 'Passkeys',
241+
columns: [
242+
{
243+
name: 'credential_id',
244+
label: 'Credential ID',
245+
primaryKey: true,
246+
},
247+
{
248+
name: 'user_id',
249+
label: 'User ID',
250+
},
251+
{
252+
name: "meta",
253+
type: AdminForthDataTypes.JSON,
254+
label: "Meta",
255+
}
256+
],
257+
plugins: [],
258+
options: {},
259+
} as AdminForthResourceInput;
260+
```
261+
262+
Add the new resource to index.ts:
263+
264+
```ts title='./index.ts'
265+
...
266+
//diff-add
267+
import passkeysResource from './resources/passkeys.js';
268+
...
269+
270+
resources: [
271+
...
272+
//diff-add
273+
passkeysResource,
274+
...
275+
],
276+
```
277+
278+
Now, update the settings of the Two-Factor Authentication plugin:
279+
280+
```ts tittle="./resources/adminuser.ts"
281+
plugins: [
282+
new TwoFactorsAuthPlugin ({
283+
twoFaSecretFieldName: 'secret2fa',
284+
timeStepWindow: 1
285+
//diff-add
286+
passkeys: {
287+
//diff-add
288+
credentialResourceID: "passkeys",
289+
//diff-add
290+
credentialIdFieldName: "credential_id",
291+
//diff-add
292+
credentialMetaFieldName: "meta",
293+
//diff-add
294+
credentialUserIdFieldName: "user_id",
295+
//diff-add
296+
settings: {
297+
//diff-add
298+
rp: {
299+
//diff-add
300+
name: "New Reality",
301+
//diff-add
302+
id: "localhost",
303+
//diff-add
304+
},
305+
//diff-add
306+
user: {
307+
//diff-add
308+
nameField: "email",
309+
//diff-add
310+
displayNameField: "email",
311+
//diff-add
312+
},
313+
//diff-add
314+
authenticatorSelection: {
315+
//diff-add
316+
authenticatorAttachment: "platform",
317+
//diff-add
318+
requireResidentKey: true,
319+
//diff-add
320+
userVerification: "required",
321+
//diff-add
322+
},
323+
//diff-add
324+
},
325+
//diff-add
326+
}
327+
}),
328+
],
329+
```
330+
331+
The setup is complete. To create a passkey:
332+
333+
> 1) Go to the user menu
334+
> 2) Click settings
335+
> 3) Select "passkeys"
336+
337+
![alt text](Passkeys1.png)
338+
339+
> 4) Add passkey
340+
341+
![alt text](Passkeys2.png)
342+
343+
344+
After adding passkey you can use passkey, instead of TOTP:
345+
346+
![alt text](Passkeys3.png)
347+
348+
> 💡 **Note**: Adding a passkey does not remove the option to use TOTP. If you lose access to your passkey, you can log in using TOTP and reset your passkey.
349+
350+
351+
352+
8.85 KB
Loading
18.9 KB
Loading
32.4 KB
Loading

0 commit comments

Comments
 (0)