File: typeorm-custom-models.md | Updated: 11/15/2025
š NextAuth.js is now part of Better Auth !
This is documentation for NextAuth.js v3, which is no longer actively maintained.
For up-to-date documentation, see the **latest version ** (v4).
Version: v3
On this page
NextAuth.js provides a set of models and schemas for the built-in TypeORM adapter that you can easily extend.
You can use these models with MySQL, MariaDB, Postgres, MongoDB and SQLite.
Creating custom modelsā
models/User.js
import Adapters from "next-auth/adapters"// Extend the built-in models using class inheritanceexport default class User extends Adapters.TypeORM.Models.User.model { // You can extend the options in a model but you should not remove the base // properties or change the order of the built-in options on the constructor constructor(name, email, image, emailVerified) { super(name, email, image, emailVerified) }}export const UserSchema = { name: "User", target: User, columns: { ...Adapters.TypeORM.Models.User.schema.columns, // Adds a phoneNumber to the User schema phoneNumber: { type: "varchar", nullable: true, }, },}
models/index.js
// To make importing them easier, you can export all models from single fileimport User, { UserSchema } from "./User"export default { User: { model: User, schema: UserSchema, },}
note
View source for built-in TypeORM models and schemas
Using custom modelsā
You can use custom models by specifying the TypeORM adapter explicitly and passing them as an option.
pages/api/auth/[...nextauth].js
import NextAuth from "next-auth"import Providers from "next-auth/providers"import Adapters from "next-auth/adapters"import Models from "../../../models"export default NextAuth({ providers: [ // Your providers ], adapter: Adapters.TypeORM.Adapter( // The first argument should be a database connection string or TypeORM config object "mysql://username:password@127.0.0.1:3306/database_name", // The second argument can be used to pass custom models and schemas { models: { User: Models.User, }, } ),})