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

@veap/auth

v0.1.6

Published

Authentication, session management, RBAC, and crypto adapters for Veap

Readme

CI Release Version

@veap/auth

Production-ready authentication, session management, RBAC, and cryptographic adapters for Veap and Next.js applications.

Overview

@veap/auth provides a modular authentication engine adhering to clean architecture principles modeled after @veap/kernel. It decouples domain entities (users, sessions, roles, permissions) and ports (hasher, token generator, cipher) into dedicated functional modules. It includes ready-to-use Next.js Server Actions, automatic database migrations, and Active Record adapters powered by @veap/database.

Architecture & Structure

Following the same modular, domain-driven structure as @veap/kernel:

src/
├── actions/        # Next.js Server Actions (signIn, signUp, signOut, etc.)
├── client/         # React hooks and context (useUser, AuthProvider)
├── common/         # Common context, routes, registry, and augmentation
├── crypto/         # Cryptography ports and adapters (bcrypt, AES, tokens)
├── migrations/     # Database migration definitions
├── models/         # ActiveRecord database models (User, Role, Session, etc.)
├── passwords/      # Password reset repositories, service, and facades
├── providers/      # AuthServiceProvider and bootstrap setup
├── rbac/           # Role-based access control repositories, service, and facades
├── session/        # Session repository, SessionService, and AuthService
├── users/          # User repository, UserService, and facades
├── validation/     # Zod input validation schemas
├── index.ts        # Main barrel entrypoint
├── server.ts       # Server-only utilities entrypoint
├── client.tsx      # React client entrypoint
├── actions.ts      # Server actions entrypoint
└── models.ts       # ActiveRecord models entrypoint

Features

  • Multi-layer authentication: Secure password hashing with bcrypt, session token generation via @oslojs/crypto, and AES secret encryption.
  • Session management: Database-backed session persistence with automatic token hashing, TTL expiry, and sliding-window extension.
  • Role-Based Access Control (RBAC): Fine-grained roles and permissions associated with users through many-to-many database relations.
  • Next.js Server Actions: First-class signIn, signUp, signOut, and getCurrentSession actions returning typed Result objects.
  • Automated migrations: Self-bootstrapping migrations for users, sessions, roles, permissions, password reset requests, and email verification.
  • Client & React hooks: Lightweight useUser() hook and AuthProvider for responsive user sessions.

Installation

# Using bun
bun add @veap/auth @veap/kernel @veap/database

# Using pnpm
pnpm add @veap/auth @veap/kernel @veap/database

# Using npm
npm install @veap/auth @veap/kernel @veap/database

Usage

Register in Application Builder

Include AuthServiceProvider in your application composition root:

import { Application } from "@veap/kernel";
import { DatabaseServiceProvider } from "@veap/database";
import { AuthServiceProvider } from "@veap/auth";

export const app = Application.configure()
  .use(DatabaseServiceProvider)
  .use(
    new AuthServiceProvider(undefined, {
      autoMigrate: true, // Automatically applies auth tables on boot
    }),
  )
  .create();

Sign In & Sign Out with Server Actions

Authenticate users in server components or server actions:

"use server";

import { signIn, signOut, getCurrentSession } from "@veap/auth";

export async function handleLogin(formData: FormData) {
  const email = formData.get("email") as string;
  const password = formData.get("password") as string;

  const result = await signIn({ email, password });

  if (!result.success) {
    return { error: result.error?.message || "Invalid credentials" };
  }

  return { user: result.data.user };
}

export async function handleLogout() {
  await signOut();
}

export async function getActiveUser() {
  const session = await getCurrentSession();
  return session?.user ?? null;
}

Querying Auth Models Directly

Interact with Active Record models provided by @veap/auth/models:

import { User, Role } from "@veap/auth/models";
import { hashPassword } from "@veap/auth/server";

// Create a new user with hashed credentials
const user = await User.create({
  name: "Jane Doe",
  email: "[email protected]",
  password: await hashPassword("securePassword123"),
  recovery_code: Buffer.from("recovery-key-bytes"),
});

// Check roles and permissions
const adminRole = await Role.query().where("name", "admin").first();
if (adminRole) {
  await user.roles().attach(adminRole.id);
}

Subpath Exports

| Export Path | Content | | ----------------------- | --------------------------------------------------------------------- | | @veap/auth | Core actions (signIn, signOut), provider, context, and schemas | | @veap/auth/client | React client components, context, and useUser hook | | @veap/auth/server | Server cryptographic utilities (hashPassword, verifyPasswordHash) | | @veap/auth/actions | Next.js Server Actions directly exportable for actions boundaries | | @veap/auth/models | Active Record models (User, Session, Role, Permission) | | @veap/auth/migrations | Knex migrations for authentication tables |

Documentation

For full guides and authentication customization, visit:

License

MIT