Skip to content

Commit b628fe4

Browse files
update docs
1 parent b0a98a0 commit b628fe4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

docs/pages/examples/totp.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ title: "Time-based one-time passwords"
44

55
# Time-based one-time passwords
66

7-
Use [`generateTOTP()`](/reference/main/generateTOTP) and [`verifyTOTP()`](/reference/main/verifyTOTP) to generate and verify HOTPs.
7+
Use [`generateTOTP()`](/reference/main/generateTOTP) to generate TOTPs and use [`verifyTOTPWithGracePeriod()`](/reference/main/verifyTOTPWithGracePeriod) or [`verifyTOTP()`](/reference/main/verifyTOTP) to verify them. Adding a grace period allows you to account for network latency and time discrepancy between devices.
88

99
```ts
10-
import { generateTOTP, verifyTOTP } from "@oslojs/otp";
10+
import { generateTOTP, verifyTOTPWithGracePeriod, verifyTOTP } from "@oslojs/otp";
1111

1212
const digits = 6;
1313
const intervalInSeconds = 30;
1414

1515
const otp = generateTOTP(key, intervalInSeconds, digits);
16-
const validOTP = verifyTOTP(key, intervalInSeconds, digits, otp);
16+
const valid = verifyTOTPWithGracePeriod(key, intervalInSeconds, digits, otp, 30);
17+
const valid = verifyTOTP(key, intervalInSeconds, digits, otp);
1718
```
1819

1920
Use [`createTOTPKeyURI()`](/reference/main/createTOTPKeyURI) to create a key URI, which are then usually encoded into a QR code.

docs/pages/reference/main/verifyTOTPWithGracePeriod.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
title: "verifyTOTPWithGracePeriod()"
33
---
44

5+
# verifyTOTPWithGracePeriod()
6+
57
Verifies a TOTP using [`verifyTOTP()`](/reference/main/verifyTOTP) with a grace period. If the grace period is 30 seconds for example, the OTP is valid if it was generated within the 30-second time span before or after the current machine time (60 seconds in total).
68

79
```ts

0 commit comments

Comments
 (0)