auth-box

raw JSON →
0.0.68 verified Sat Apr 25 auth: no javascript

auth-box is an authentication library for Node.js >=6 that aims to provide a unified interface for multiple authentication providers. Currently at version 0.0.68, it is in early development with an unstable API and frequent breaking changes. Key differentiator: attempts to abstract away the differences between various auth services into a single 'auth box' but lacks documentation and maturity.

error TypeError: Cannot read property 'access_token' of undefined
cause OAuth token response is malformed or provider returns error without proper handling.
fix
Check network request; ensure redirect URI matches provider settings. Use try-catch around authenticate().
error Error: Provider 'facebook' not supported
cause The provider name is not in the supported list or typo.
fix
Use one of the supported provider names from the Providers enum; check for exact casing.
breaking Token storage changed from synchronous to asynchronous in v0.0.50
fix Update code to handle async token storage; see migration guide (if any).
deprecated Provider 'twitter' is deprecated and will be removed in v1.0
fix Use 'twitter-v2' provider instead.
gotcha The package has no README or documentation. API is inferred from source code and may change without notice.
fix Pin exact version and extensively test on upgrade.
gotcha AuthBox constructor throws if any required config field is missing; error messages are unhelpful.
fix Ensure all provider config objects include required fields as per source comments.
npm install auth-box
yarn add auth-box
pnpm add auth-box

Initializes AuthBox with OAuth configs for Google and GitHub, then authenticates a user with an authorization code.

import AuthBox, { authenticate, Providers } from 'auth-box';

const config = {
  google: {
    clientId: process.env.GOOGLE_CLIENT_ID ?? '',
    clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? ''
  },
  github: {
    clientId: process.env.GITHUB_CLIENT_ID ?? '',
    clientSecret: process.env.GITHUB_CLIENT_SECRET ?? ''
  }
};

const box = new AuthBox(config);

async function main() {
  try {
    const user = await authenticate('google', { code: 'auth_code' });
    console.log(user);
  } catch (err) {
    console.error('Authentication failed:', err.message);
  }
}

main();