Skip to content

Commit a61140d

Browse files
committed
Merge branch 'SettingsView' of https://github.com/devforth/adminforth into SettingsView
2 parents 6b3c386 + 9505778 commit a61140d

File tree

4 files changed

+163
-1
lines changed

4 files changed

+163
-1
lines changed

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

Lines changed: 163 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,166 @@ 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+
And make migration:
232+
233+
```bash
234+
npm run makemigration -- --name add-passkeys ; npm run migrate:local
235+
```
236+
237+
238+
Next, you need to create a new resource for passkeys:
239+
240+
```ts title='./resources/passkeys.ts'
241+
import { AdminForthDataTypes, AdminForthResourceInput } from "../../adminforth";
242+
243+
export default {
244+
dataSource: 'maindb',
245+
table: 'passkeys',
246+
resourceId: 'passkeys',
247+
label: 'Passkeys',
248+
columns: [
249+
{
250+
name: 'credential_id',
251+
label: 'Credential ID',
252+
primaryKey: true,
253+
},
254+
{
255+
name: 'user_id',
256+
label: 'User ID',
257+
},
258+
{
259+
name: "meta",
260+
type: AdminForthDataTypes.JSON,
261+
label: "Meta",
262+
}
263+
],
264+
plugins: [],
265+
options: {},
266+
} as AdminForthResourceInput;
267+
```
268+
269+
Add the new resource to index.ts:
270+
271+
```ts title='./index.ts'
272+
...
273+
//diff-add
274+
import passkeysResource from './resources/passkeys.js';
275+
...
276+
277+
resources: [
278+
...
279+
//diff-add
280+
passkeysResource,
281+
...
282+
],
283+
```
284+
285+
Now, update the settings of the Two-Factor Authentication plugin:
286+
287+
```ts tittle='./resources/adminuser.ts'
288+
plugins: [
289+
new TwoFactorsAuthPlugin ({
290+
twoFaSecretFieldName: 'secret2fa',
291+
timeStepWindow: 1
292+
//diff-add
293+
passkeys: {
294+
//diff-add
295+
credentialResourceID: "passkeys",
296+
//diff-add
297+
credentialIdFieldName: "credential_id",
298+
//diff-add
299+
credentialMetaFieldName: "meta",
300+
//diff-add
301+
credentialUserIdFieldName: "user_id",
302+
//diff-add
303+
settings: {
304+
// diff-add
305+
// relying party config
306+
//diff-add
307+
rp: {
308+
//diff-add
309+
name: "New Reality",
310+
// diff-add
311+
// id should be a app domain name without port
312+
// diff-add
313+
// e.g. if you run locally in https://localhost:3500 -> then write "localhost"
314+
// diff-add
315+
// if you run at https://myadmin.myproduct.com -> write "myadmin.myproduct.com"
316+
//diff-add
317+
id: "localhost",
318+
//diff-add
319+
},
320+
//diff-add
321+
user: {
322+
//diff-add
323+
nameField: "email",
324+
//diff-add
325+
displayNameField: "email",
326+
//diff-add
327+
},
328+
//diff-add
329+
authenticatorSelection: {
330+
// diff-add
331+
// Can be "platform" or "cross-platform"
332+
//diff-add
333+
authenticatorAttachment: "platform",
334+
//diff-add
335+
requireResidentKey: true,
336+
//diff-add
337+
userVerification: "required",
338+
//diff-add
339+
},
340+
//diff-add
341+
},
342+
//diff-add
343+
}
344+
}),
345+
],
346+
```
347+
> ☝️ most likely you should set `passkeys.settings.rp.id` it from your process.env depending on your env
348+
349+
The setup is complete. To create a passkey:
350+
351+
> 1) Go to the user menu
352+
> 2) Click settings
353+
> 3) Select "passkeys"
354+
355+
![alt text](Passkeys1.png)
356+
357+
> 4) Add passkey
358+
359+
![alt text](Passkeys2.png)
360+
361+
362+
After adding passkey you can use passkey, instead of TOTP:
363+
364+
![alt text](Passkeys3.png)
365+
366+
> 💡 **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.
367+
368+
369+
370+
8.85 KB
Loading
18.9 KB
Loading
32.4 KB
Loading

0 commit comments

Comments
 (0)