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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@nexusauth/prisma-adapter

v0.1.2

Published

Prisma adapter for NexusAuth - Modern database toolkit integration with schema mapping

Readme

@nexusauth/prisma-adapter

Prisma adapter for NexusAuth with support for schema mapping to existing databases.

Features

  • Schema Mapping: Map to existing database columns and table names
  • Type-Safe: Full TypeScript support with Prisma's generated types
  • Flexible: Works with any Prisma-supported database
  • Lightweight: Uses peerDependencies to avoid duplicate installations
  • Production Ready: Battle-tested adapter implementation

Installation

npm install @nexusauth/core @nexusauth/prisma-adapter @prisma/client
# or
pnpm add @nexusauth/core @nexusauth/prisma-adapter @prisma/client
# or
yarn add @nexusauth/core @nexusauth/prisma-adapter @prisma/client

Requirements

  • @prisma/client: ^5.0.0 || ^6.0.0
  • @nexusauth/core: workspace:*

Basic Usage

1. Define your Prisma Schema

// prisma/schema.prisma
model User {
  id                       String    @id @default(cuid())
  email                    String    @unique
  name                     String?
  password                 String?
  emailVerified            DateTime?
  image                    String?
  resetToken               String?
  resetTokenExpiry         DateTime?
  verificationToken        String?
  verificationTokenExpiry  DateTime?
  createdAt                DateTime  @default(now())
  updatedAt                DateTime  @updatedAt

  accounts                 Account[]
  sessions                 Session[]
}

model Account {
  id                String   @id @default(cuid())
  userId            String
  provider          String
  providerAccountId String
  accessToken       String?
  refreshToken      String?
  expiresAt         DateTime?
  tokenType         String?
  scope             String?
  idToken           String?
  createdAt         DateTime @default(now())
  updatedAt         DateTime @updatedAt

  user              User     @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([provider, providerAccountId])
}

model Session {
  id                   String    @id @default(cuid())
  sessionToken         String    @unique
  userId               String
  expires              DateTime
  refreshToken         String?   @unique
  refreshTokenExpires  DateTime?
  createdAt            DateTime  @default(now())
  updatedAt            DateTime  @updatedAt

  user                 User      @relation(fields: [userId], references: [id], onDelete: Cascade)
}

2. Configure NexusAuth with Prisma Adapter

import { NexusAuth } from '@nexusauth/core';
import { PrismaAdapter } from '@nexusauth/prisma-adapter';
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

const auth = new NexusAuth({
  adapter: PrismaAdapter({
    client: prisma,
  }),
  secret: process.env.AUTH_SECRET!,
  jwt: {
    expiresIn: '7d',
  },
});

Advanced Usage: Schema Mapping

If you have an existing database with custom column names, you can map them:

Existing Legacy Schema

model LegacyUser {
  user_id              String    @id @default(cuid()) @map("user_id")
  email_address        String    @unique @map("email_address")
  full_name            String?   @map("full_name")
  hashed_password      String?   @map("hashed_password")
  email_confirmed_at   DateTime? @map("email_confirmed_at")
  profile_picture      String?   @map("profile_picture")
  password_reset_token String?   @map("password_reset_token")
  password_reset_exp   DateTime? @map("password_reset_exp")
  created_at           DateTime  @default(now()) @map("created_at")
  updated_at           DateTime  @updatedAt @map("updated_at")

  @@map("users")
}

Configure with Field Mapping

const auth = new NexusAuth({
  adapter: PrismaAdapter({
    client: prisma,

    // Map table names
    tableNames: {
      user: 'legacyUser',     // Prisma model name
      account: 'userAccount',
      session: 'userSession',
    },

    // Map field names
    fieldMapping: {
      user: {
        id: 'user_id',
        email: 'email_address',
        name: 'full_name',
        password: 'hashed_password',
        emailVerified: 'email_confirmed_at',
        image: 'profile_picture',
        resetToken: 'password_reset_token',
        resetTokenExpiry: 'password_reset_exp',
        createdAt: 'created_at',
        updatedAt: 'updated_at',
      },
    },
  }),
  secret: process.env.AUTH_SECRET!,
});

API Reference

PrismaAdapter(config)

Creates a Prisma adapter instance for NexusAuth.

Parameters

  • config.client (required): PrismaClient instance
  • config.fieldMapping (optional): Object mapping NexusAuth fields to your database columns
    • user: User field mappings
    • account: Account field mappings
    • session: Session field mappings
  • config.tableNames (optional): Object mapping NexusAuth table names to your Prisma model names
    • user: User model name (default: 'user')
    • account: Account model name (default: 'account')
    • session: Session model name (default: 'session')

Returns

BaseAdapter - Adapter implementation compatible with NexusAuth

Examples

Using with Next.js

// lib/auth.ts
import { NexusAuth } from '@nexusauth/core';
import { PrismaAdapter } from '@nexusauth/prisma-adapter';
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

export const auth = new NexusAuth({
  adapter: PrismaAdapter({ client: prisma }),
  secret: process.env.AUTH_SECRET!,
});

Using with Express

import express from 'express';
import { NexusAuth } from '@nexusauth/core';
import { PrismaAdapter } from '@nexusauth/prisma-adapter';
import { PrismaClient } from '@prisma/client';

const app = express();
const prisma = new PrismaClient();

const auth = new NexusAuth({
  adapter: PrismaAdapter({ client: prisma }),
  secret: process.env.AUTH_SECRET!,
});

app.post('/api/auth/register', async (req, res) => {
  const { email, password, name } = req.body;

  try {
    const result = await auth.register({ email, password, name });
    res.json(result);
  } catch (error) {
    res.status(400).json({ error: error.message });
  }
});

Supported Databases

Since this adapter uses Prisma, it supports all databases that Prisma supports:

  • PostgreSQL
  • MySQL
  • SQLite
  • SQL Server
  • MongoDB
  • CockroachDB

License

MIT