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

post-arafat-test

v2.20.0

Published

## **πŸ“Œ Overview**

Readme

πŸ“¦ My Auth Package

πŸ“Œ Overview

This authentication package provides a ready-to-use database schema for user management using Drizzle ORM. The schema includes essential tables for users, roles, permissions, authentication tokens, and account linking.

These schema files will be automatically generated in your project when you install and use this package, ensuring a consistent database structure for authentication and authorization.


πŸ“₯ Schema Files

After installing the package, the following schema files will be created under src/db/schema/user-management:

1️⃣ Users Table (users.ts)

Manages user accounts with fields for email, password, role, verification status, and timestamps.

const usersTable = pgTable("users", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),
  email: varchar({ length: 91 }).notNull().unique(),
  password: varchar({ length: 91 }).notNull(),
  isVerified: boolean().notNull().default(false),
  isDeleted: boolean().notNull().default(false),
  registeredAt: timestamp("registered_at"),
  createdAt: timestamp("created_at").notNull().defaultNow(),
  updatedAt: timestamp("updated_at").notNull().defaultNow(),
  roleId: integer("role_id")
    .references(() => rolesTable.id)
    .notNull(),
});

βœ… Supports user authentication and role-based access control (RBAC).


2️⃣ Roles Table (roles.ts)

Defines user roles such as Admin, Moderator, User, etc..

const rolesTable = pgTable("roles", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),
  name: varchar({ length: 91 }).notNull().unique(),
  description: text(),
  createdAt: timestamp("created_at").notNull().defaultNow(),
  updatedAt: timestamp("updated_at").notNull().defaultNow(),
});

βœ… Used for assigning roles to users.


3️⃣ Permissions Table (permissions.ts)

Stores granular permissions for different features.

const permissionsTable = pgTable("permissions", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),
  name: varchar({ length: 91 }).notNull().unique(),
  description: text(),
  createdAt: timestamp("created_at").notNull().defaultNow(),
  updatedAt: timestamp("updated_at").notNull().defaultNow(),
});

βœ… Useful for defining fine-grained access controls.


4️⃣ Permission-to-Roles Table (permission_roles.ts)

Links roles to permissions.

const permissionToRolesTable = pgTable(
  "permission_to_roles",
  {
    permissionId: integer("permission_id").references(
      () => permissionsTable.id
    ),
    roleId: integer("role_id").references(() => rolesTable.id),
  },
  (t) => ({
    unq: unique().on(t.permissionId, t.roleId),
  })
);

βœ… Allows mapping multiple permissions to a single role.


5️⃣ User-Accounts Table (user_accounts.ts)

Links users to external authentication providers (OAuth, etc.).

const usersToAccountsTable = pgTable("users_to_accounts", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),
  userId: integer("user_id").references(() => usersTable.id),
  accountId: integer("account_id").references(() => accountsTable.id),
});

βœ… Used for third-party login integrations (Google, GitHub, etc.).


6️⃣ Refresh Tokens Table (refresh_tokens.ts)

Manages JWT refresh tokens for authentication.

const refreshTokensTable = pgTable("refresh_tokens", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),
  token: text().notNull(),
  userId: integer("user_id").notNull(),
  expiresAt: timestamp("expires_at").notNull(),
  createdAt: timestamp("created_at").notNull().defaultNow(),
  deviceInfo: varchar({ length: 255 }).notNull(),
  updatedAt: timestamp("updated_at").notNull().defaultNow(),
});

βœ… Supports secure session handling with refresh tokens.


7️⃣ Accounts Table (accounts.ts)

Stores authentication provider details.

const accountsTable = pgTable("accounts", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),
  provider_name: varchar({ length: 91 }).notNull(),
});

βœ… Used for external authentication providers.


** Zod Schema Validations (authValidation.ts)**

import { z } from "zod";

export const registerUserSchema = z.object({
  email: z.string().email(),
  password: z.string().min(8),
  confirmPassword: z.string().min(8),
});

export const verifyOnRegisterSchema = z.object({
  token: z.string(),
  code: z.string(),
  email: z.string().email(),
});

export const loginUserSchema = z.object({
  email: z.string().email(),
  password: z.string().min(8),
});

export const forgotPasswordSchema = z.object({
  email: z.string().email(),
});

export const verifyOnResetPasswordSchema = z.object({
  code: z.string(),
  token: z.string(),
  email: z.string().email(),
  password: z.string().min(8),
  confirmPassword: z.string().min(8),
});

βœ… Used for external authentication providers.


πŸ“– How to Use

1️⃣ Install the Package

npm install my-auth-package

2️⃣ Generate Schema Files

After installation, run the following command to generate the database schema:

npm run generate-schema

This will create all the schema files under:

src/db/schema/user-management/

3️⃣ Apply Schema to Database

To apply the schema to your database, use Drizzle ORM migrations:

drizzle-kit push

βœ… Now, your authentication system is fully set up! πŸŽ‰


πŸ”Ή Why Use This Schema?

  • βœ… Pre-configured for authentication & authorization
  • βœ… Supports role-based access control (RBAC)
  • βœ… Easily extendable and customizable
  • βœ… Works with Drizzle ORM for better database management

πŸ“Œ Next Steps

  • [ ] Customize the schema (Add custom fields like full_name, profile_picture, etc.)
  • [ ] Set up authentication logic (Use the schema with authentication flows)
  • [ ] Deploy the database (Connect to PostgreSQL and run migrations)

πŸš€ Get Started Today!

This package automates schema generation for authentication-based applications. Simply install, run the generator, and start using role-based authentication in your project! πŸš€


Would you like me to add versioning instructions for when new fields are added? 😊