Skip to content

Zastinian/better-auth-typeorm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📦 @hedystia/better-auth-typeorm

TypeORM adapter for Better Auth - Powerful database integration for your auth system! 🚀

npm version npm downloads license

🌟 Features

  • 🗄️ Database Agnostic: Works with all TypeORM-supported databases (MySQL, PostgreSQL, SQLite, etc.)
  • 🔄 CRUD Operations: Full support for create, read, update, and delete operations
  • Efficient Queries: Built-in pagination, sorting, and filtering support
  • 🔒 Secure Operations: Proper transaction handling and error management

🚀 Quick Start

  1. Install the package:
npm install @hedystia/better-auth-typeorm typeorm
  1. Generate TypeORM Entities and Migrations

Before you can use the adapter, you need to generate the necessary entities and migrations for your database. You can do this using the Better Auth CLI:

bunx @better-auth/cli generate
# or
npx @better-auth/cli generate

This command will create the typeorm/entities and typeorm/migrations directories in your project.

  1. Create your TypeORM DataSource configuration:
import { DataSource } from "typeorm";
import path from "path";

export const dataSource = new DataSource({
  type: "mysql",
  host: "localhost",
  port: 3306,
  username: "your_username",
  password: "your_password",
  database: "your_database",
  entities: [path.join(__dirname, "typeorm/entities/**/*.ts")],
  migrations: [path.join(__dirname, "typeorm/migrations/**/*.ts")],
  migrationsRun: true,
});

await dataSource.initialize();
  1. Set up your Better Auth configuration:
import { betterAuth } from "better-auth";
import { typeormAdapter } from "@hedystia/better-auth-typeorm";
import { organization, twoFactor } from "better-auth/plugins";
import { dataSource } from "./data-source";

export const auth = betterAuth({
  database: typeormAdapter(dataSource),
  plugins: [organization(), twoFactor()],
});

🌟 Why use this adapter?

  • Seamless Integration: Direct mapping between Better Auth entities and TypeORM
  • Flexible Database Support: Use with any TypeORM-supported database
  • Production Ready: Built-in error handling and transaction support
  • Performance Optimized: Efficient query building and data transformation

📝 License

This project is licensed under the MIT License.

🙏 Acknowledgements

About

A typeorm adapter for better-auth

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •