Auth Strategy Manager

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

Meta package for auth-strategy-manager that installs the core package by default. Version 2.0.2 ships bundled TypeScript types, supports Node.js and browser environments with ESM and CJS exports. It provides a unified strategy-based authentication and authorization abstraction layer, simplifying integration of multiple auth providers (e.g., JWT, OAuth, API keys) behind a consistent interface. Key differentiators include zero-config core setup via the meta package, first-class TypeScript support, and a plugin-style strategy architecture that avoids runtime dependencies beyond the core.

error Cannot find module '@auth-strategy-manager/core' or its corresponding type declarations.
cause Missing dependency: need to install @auth-strategy-manager/core separately or ensure meta package installs it correctly.
fix
Run: npm install @auth-strategy-manager/core
error TypeError: authStrategyManager.use is not a function
cause Attempting to call .use() on an improperly initialized manager (e.g., using default import from meta package instead of core).
fix
Ensure you import AuthStrategyManager from '@auth-strategy-manager/core', not from 'auth-strategy-manager'.
error ERR_REQUIRE_ESM: require() of ES Module not supported
cause Using require() to import an ESM-only package.
fix
Use import statement or dynamic import: const { AuthStrategyManager } = await import('@auth-strategy-manager/core');
breaking v2.0.0 renamed package from 'auth-manager-core' to '@auth-strategy-manager/core'. All imports must be updated.
fix Replace 'auth-manager-core' with '@auth-strategy-manager/core' in imports and package.json dependencies.
breaking v2.0.0 dropped support for CommonJS (require). Package is ESM-only. Requires Node >=14 or bundler support.
fix Use import syntax. For CJS environments, use dynamic import: const { AuthStrategyManager } = await import('@auth-strategy-manager/core');
deprecated v1.x strategy options with 'algorithm' property are deprecated in v2. Use 'algorithms' array instead.
fix Replace 'algorithm: 'HS256'' with 'algorithms: ['HS256']'.
gotcha The meta package 'auth-strategy-manager' is a side-effects-only package; it does not export any symbols. Attempting to import named exports from it will fail.
fix Import directly from '@auth-strategy-manager/core' for any symbols.
npm install auth-strategy-manager
yarn add auth-strategy-manager
pnpm add auth-strategy-manager

Initializes the Auth Strategy Manager, registers a JWT strategy with secret from environment variable, and authenticates a token.

import { AuthStrategyManager } from '@auth-strategy-manager/core';

const manager = new AuthStrategyManager();

// Define a simple JWT strategy
manager.use('jwt', {
  type: 'jwt',
  secret: process.env.JWT_SECRET ?? 'fallback-secret',
  verify: async (token) => {
    // verify logic
    return { userId: '123' };
  }
});

// Authenticate a request
async function authenticate(token: string) {
  const result = await manager.authenticate('jwt', token);
  if (result.success) {
    console.log('User:', result.payload);
  } else {
    console.error('Auth failed:', result.error);
  }
}

authenticate('some-token');