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

@promedev/auth-core

v1.0.0

Published

Reusable authentication core library by Promedev

Readme

auth-core

Lightweight authentication core (JWT + refresh tokens + OAuth provider interfaces).

This package is designed as a small, testable authentication module for learning and small projects. It exposes AuthCore, domain types, and a few in-memory infra implementations.

Quick start

Install (if published):

npm install auth-core

Local development (from this repo):

npm ci
npm run build
npm test

Usage

Important: the library does not load environment files itself. Your application is responsible for providing environment variables (e.g. JWT_SECRET) or injecting dependencies. This avoids side-effects when importing the library.

Factory (recommended)

The easiest way to get started is with the createAuthCore factory. It sets up AuthCore with in-memory storage and reads environment variables for JWT configuration.

// 1. Load environment variables (e.g. from .env file)
import "dotenv/config";

// 2. Create the AuthCore instance
import { createAuthCore } from "auth-core";

const auth = createAuthCore();

// 3. Use it
const user = await auth.signUp("[email protected]", "password");
const tokens = await auth.signIn("[email protected]", "password");
console.log(tokens.accessToken);

The factory requires JWT_SECRET to be set in your environment. You can also set JWT_ACCESS_TOKEN_EXPIRES_IN and JWT_REFRESH_TOKEN_EXPIRES_IN.

Dependency Injection (advanced)

For more control or to use your own infrastructure (e.g. a database user repository), you can inject dependencies into the services and then create an AuthCore instance manually.

import { AuthCore } from "auth-core";
import { AuthService, UserService } from "auth-core/core";
import { JwtService } from "auth-core/domain";
import { MemoryUserRepo, MemoryTokenStore } from "auth-core/infra";
import { PasswordService } from "auth-core/domain";

// 1. Create infrastructure components
const userRepo = new MemoryUserRepo();
const tokenStore = new MemoryTokenStore();

// 2. Create domain services
const passwordService = new PasswordService();
const jwtService = new JwtService({
  jwtSecret: process.env.JWT_SECRET!,
  accessTokenExpiresIn: "1h",
  refreshTokenExpiresIn: "7d",
});

// 3. Create core services
const userService = new UserService(userRepo, passwordService);
const authService = new AuthService(
  userRepo,
  tokenStore,
  passwordService,
  jwtService
);

// 4. Create the AuthCore instance
const auth = new AuthCore(userService, authService);

Quick example: sign up / sign in

const user = await auth.signUp("[email protected]", "password");
const tokens = await auth.signIn("[email protected]", "password");
console.log(tokens.accessToken, tokens.refreshToken);

Testing and CI

Tests rely on JWT_SECRET being set. For local development we provide a Jest setup that injects a test secret. In CI, set JWT_SECRET as an environment variable or secret.

CI example (GitHub Actions):

env:
  JWT_SECRET: ${{ secrets.JWT_SECRET }}
steps:
  - uses: actions/checkout@v3
  - run: npm ci
  - run: npm test

Security notes

  • Do not commit secrets into source control.
  • For production, use a secure secret manager and avoid storing refresh tokens in plaintext.
  • Consider hashing refresh tokens before persisting (e.g. store sha256(token) instead of the token itself).

Publishing notes

  • The library does not load environment variables by itself. Load .env at your application entry point or use a secrets manager to inject required values.
  • package.json files is configured to include only the dist artifact in the published package. Test and config files are not included in the published package.
  • Minimum Node version is >=18 (see project package.json).

Node / Environment

This package requires Node >= 18 (uses crypto.randomUUID() and relies on Node runtime capabilities). If you need wider support, consider polyfills or shims.

Contributing

PRs are welcome. Keep tests green and follow semantic versioning for releases.