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.
Common errors
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.
Warnings
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.
Install
npm install auth-box yarn add auth-box pnpm add auth-box Imports
- AuthBox wrong
const AuthBox = require('auth-box'); // Wrong: No default export in some versionscorrectimport AuthBox from 'auth-box' - authenticate wrong
const authenticate = require('auth-box').authenticate; // May work but not recommended in ESM contextcorrectimport { authenticate } from 'auth-box' - Providers wrong
import { providers } from 'auth-box';correctimport { Providers } from 'auth-box'
Quickstart
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();