# How to bypass time-based 2FA login flows with Playwright

Humanless lets your own app's test account complete TOTP 2FA instead of bypassing it, because a TOTP code is computed from a shared secret and the clock, so whoever holds the secret can produce the current code. Create an identity with the `totp` channel, enroll its `totp_secret` on the test user (through a seed script, an admin API or a "can't scan? enter a key" field that accepts your key), then call `getTotp` at login. It returns `{ code, seconds_remaining }`. If 3 seconds or fewer remain, wait for the next window. Today, Humanless generates the secret; it doesn't import one your app created.

```ts totp-login.spec.ts
let t = await hl.getTotp(identity_id);
if (t.seconds_remaining <= 3) {
  await page.waitForTimeout((t.seconds_remaining + 1) * 1000);
  t = await hl.getTotp(identity_id);
}
await page.getByLabel("Authentication code").fill(t.code);
await page.getByRole("button", { name: "Verify" }).click();
```

## Other options

- **otplib** (Node) or **pyotp** (Python): read the secret from the enrollment screen or the `otpauth://` URI, store it with the test user and generate codes in the test. This is the usual choice when your app generates the secret.
- **Seed a user with 2FA already on** so most tests skip the enrollment UI, and keep one test that enrolls for real.
- For passkeys rather than TOTP, Chromium's virtual authenticator (via a CDP session) replaces the hardware key.

> **Use policy:** Only for test accounts on apps you own or are authorized to test, never to get around 2FA on someone else's account or service. See the [Terms](/terms).

More: [How to test TOTP / authenticator 2FA in E2E tests](/guides/totp-e2e-testing) · [All answers](/answers/)

Last updated 2026-12-04

Canonical: https://usehumanless.com/answers/how-to-bypass-time-based-2fa-login-flows-with-playwright

---
More: https://usehumanless.com/llms.txt
