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

@dravyn/auth-js

v0.4.1

Published

Official JS/React SDK for Dravyn Auth — register/login/OTP/MFA/orgs, matches the Dravyn Auth backend API exactly.

Readme

@dravyn/auth-js

Official JS/React SDK for Dravyn Auth — register, OTP verification, login, MFA, sessions, organisations, and Google/GitHub OAuth, matching the Dravyn Auth backend API exactly.


Installation

npm install @dravyn/auth-js

Peer dependency: react >=18 — only required if you use the @dravyn/auth-js/react entry point. The core client works in any JS environment (Node, React Native, vanilla browser).


Quick start (framework-agnostic)

import { DravynAuthClient } from '@dravyn/auth-js';

const auth = new DravynAuthClient({
  baseUrl: 'https://your-dravyn-auth-instance.com',
  publicKey: 'pk_your_project_key', // omit to use the deployment's default project
});

await auth.register('[email protected]', 'correct-horse-battery-staple');
await auth.verifyOtp('[email protected]', '123456'); // signs in on success

// login() returns the user, OR { mfaRequired: true, mfaToken } if MFA is enabled
const result = await auth.login('[email protected]', 'correct-horse-battery-staple');
if ('mfaRequired' in result) {
  await auth.completeMfaChallenge(result.mfaToken, '482913');
}

// Roles/permissions are on the user object — no extra API call needed
const me = auth.getUser(); // { id, email, roles: ['admin'], permissions: [...], ... }

// Authenticated fetch helper for calling your own backend
const res = await auth.fetchAuthed('/api/my-endpoint'); // attaches + refreshes the bearer token

React

import { AuthProvider, useAuth } from '@dravyn/auth-js/react';

function Root() {
  return (
    <AuthProvider baseUrl="https://your-dravyn-auth-instance.com" publicKey="pk_...">
      <App />
    </AuthProvider>
  );
}

function LoginForm() {
  const { login, completeMfaChallenge, user, isAuthenticated, logout } = useAuth();
  // login(email, password) → throws DravynAuthError on failure, with .code
}

Wrap anything behind auth in <ProtectedRoute fallback={<LoginForm />}>.

Tokens persist to localStorage by default. For React Native / Expo, pass a storage adapter backed by @react-native-async-storage/async-storage:

new DravynAuthClient({
  baseUrl: '...',
  storage: {
    getItem: AsyncStorage.getItem,
    setItem: AsyncStorage.setItem,
    removeItem: AsyncStorage.removeItem,
  },
});

MFA

const { qrCodeDataUrl, secret } = await auth.setupMfa();
// render qrCodeDataUrl as an <img>, user scans it with their authenticator app, then:
const { backupCodes } = await auth.confirmMfaSetup('482913'); // show these once
await auth.disableMfa();

Organizations

const org = await auth.createOrg('Acme Workspace');
await auth.inviteOrgMember(org.id, '[email protected]');
const orgs = await auth.listOrgs();
const members = await auth.listOrgMembers(org.id);

OAuth (Google / GitHub)

window.location.href = auth.getGoogleUrl(); // or auth.getGithubUrl()

// On the page the provider redirects back to:
const user = await auth.completeOAuthFromUrl(); // reads window.location, signs in

Sessions

const sessions = await auth.listSessions(); // device, IP, last active
await auth.revokeSession(sessionId);

Errors

Every failed call throws DravynAuthError, with .message, .code, .status, and .details:

import { DravynAuthError } from '@dravyn/auth-js';

try {
  await auth.login(email, password);
} catch (err) {
  if (err instanceof DravynAuthError && err.code === 'INVALID_CREDENTIALS') {
    // ...
  }
}

License

MIT