npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@frogbotai/plugin-two-factor

v0.43.0

Published

Two-factor sign-in for FrogBot: authenticator codes and recovery codes after the password or sign-in provider.

Readme

@frogbotai/plugin-two-factor

Two-factor sign-in for FrogBot. After the password or a sign-in provider, a user with it on enters a code from an authenticator app or a recovery code before they get a session. No session exists until the code is accepted.

Full guide: Two-factor sign-in.

Setup

pnpm add @frogbotai/plugin-two-factor
import { twoFactor } from '@frogbotai/plugin-two-factor';
import { buildConfig } from 'frogbot';

export default buildConfig({
  secret: process.env.FROGBOT_SECRET!,
  db: databaseAdapter,
  collections: [{ slug: 'users', auth: true, fields: [{ name: 'role', type: 'text' }] }],
  plugins: [
    twoFactor({
      issuer: 'Acme',
      require: ({ user }) => user.role === 'admin',
      canReset: ({ req, user }) => req.user?.role === 'admin' && user.role !== 'owner',
    }),
  ],
});

Run frogbot generate:importmap in build-only workflows after adding the plugin; frogbot dev does it for you.

The plugin adds twoFactorEnabled (read-only, with the account section) and three hidden fields to the auth collection: the TOTP secret, encrypted with connections.encryption; the recovery codes, hashed; and the last accepted time step.

Options

| Option | Default | Description | | -------------------------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------- | | collection | admin.user | Auth collection that gets two-factor sign-in. | | require({ req, user }) | nobody | Users who must have it: setup at the next sign-in, and they can't turn it off. | | canEnable({ req, user }) | everyone | Users who may turn it on; false gives 403. | | canReset({ req, user }) | nobody | Whether the signed-in user may reset user's. Asked only for a user they can read and update. | | issuer | 'FrogBot' | Name authenticator apps show. | | emails | built-in | Replace an event's email (enabled, disabled, recoveryCodeUsed, recoveryCodesCreated, reset) or turn it off with false. | | keysURL | none | Where users manage API keys; the account section's "API keys aren't affected" note links to it. |

Turning it on

The user's account section shows a QR code and the key as text, asks for a current code, then shows 10 recovery codes once with copy and download. Turning it on ends every other session of that user (with auth.useSessions: false, issued tokens stay valid until they expire). New recovery codes needs a code and voids the old set; Turn off needs a code or a recovery code. API keys aren't affected.

Codes are RFC 6238 (SHA-1, 30 s, one step of drift), each usable once. Five wrong codes in 10 minutes lock code entry for that user for 10 minutes.

Require

A required user without two-factor sign-in goes to setup at their next sign-in, before any session exists, including the first user at registration. While require returns true, Turn off is hidden and POST /two-factor/disable answers 403.

Recovery and reset

A recovery code signs in once. After using one, the code page says how many are left and, at 3 or fewer, advises making new ones, with a link to the account page for the admin's user collection only (other auth collections get the advice without a link); JSON clients get recoveryCodesLeft. When canReset allows it, another user's document shows Reset two-factor sign-in: it removes their secret and codes, ends every session (with auth.useSessions: false, issued tokens stay valid until they expire) and clears the lock. canReset is asked only for a user the admin can read and update. Nobody can reset their own.

Sessions and password login

  • Sign-in methods pause in the collection's beforeSignIn hook and redirect to the code page at /api/<collection>/two-factor.
  • The admin's login view is replaced (unless the app sets admin.components.views.login) by one with the same slots whose form follows the code step.
  • POST /api/<collection>/login answers 202 { message, twoFactor: 'code' | 'setup', url } with no token. Post { code } to <url>/verify with the returned cookie for the normal login response. A returnTo path in the login body makes the code page continue there.
  • POST /api/<collection>/reset-password saves the password and ends every session, but signs nobody in who needs a code: { message, twoFactor: 'signIn' }. GraphQL and the Local API resetPassword save it too and return no token.

The paused sign-in is a 10-minute, single-use KV record behind an HttpOnly, SameSite=Lax cookie scoped to the code endpoints. It grants no access on its own.

Limits

  • GraphQL loginUser and the Local API login have no code step and fail for users who need a code or setup.
  • canReset defaults to nobody: without it, a user who loses their authenticator and recovery codes can't get back in.
  • Another pausing beforeSignIn hook (a terms step, say) can't be combined yet: resuming it with finishSignIn for a user who needs a code is refused with 403.
  • No passkeys, security keys or per-tenant settings.