https://github.com/ronin-co/better-auth
A Better Auth adapter for RONIN
https://github.com/ronin-co/better-auth
auth better-auth betterauth ronin ts typescript
Last synced: 1 day ago
JSON representation
A Better Auth adapter for RONIN
- Host: GitHub
- URL: https://github.com/ronin-co/better-auth
- Owner: ronin-co
- License: apache-2.0
- Created: 2025-04-08T11:40:39.000Z (8 days ago)
- Default Branch: main
- Last Pushed: 2025-04-09T13:05:58.000Z (7 days ago)
- Last Synced: 2025-04-11T15:05:41.214Z (5 days ago)
- Topics: auth, better-auth, betterauth, ronin, ts, typescript
- Language: TypeScript
- Homepage: https://npmjs.com/package/@ronin/better-auth
- Size: 52.7 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - Link
README
# Better Auth + RONIN
[](https://github.com/ronin-co/better-auth/actions/workflows/validate.yml)
[](https://codecov.io/github/ronin-co/better-auth)
[](https://packagephobia.com/result?p=@ronin/better-auth)A [Better Auth adapter](https://www.better-auth.com/docs/concepts/database#adapters) for storing session data in [RONIN](https://ronin.co/) with ease.
## Usage
```typescript
import { betterAuth } from 'better-auth';
import { ronin } from "@ronin/better-auth";const auth = betterAuth({
database: ronin(),
// ...
});
```Or if you want to use a custom client instance:
```typescript
import { betterAuth } from 'better-auth';
import { ronin } from "@ronin/better-auth";
import { createSyntaxFactory } from 'ronin';const client = createSyntaxFactory({
token: process.env.RONIN_TOKEN,
});const auth = betterAuth({
database: ronin(client),
// ...
});
```## Schema
Better Auth requires a number of schema models / tables to be created in your database. This is referred to in the Better Auth documentation as the "core schema".
To help get started, here is that "core schema" translated to a RONIN database schema:
```ts
// schema/index.tsimport { blob, boolean, date, link, model, string } from 'ronin/schema';
export const User = model({
slug: 'user',
fields: {
email: string({ required: true, unique: true }),
emailVerified: boolean({ required: true }),
image: blob(),
name: string({ required: true }),
},
});export const Session = model({
slug: 'session',
fields: {
expiresAt: date({ required: true }),
ipAddress: string(),
token: string({ required: true, unique: true }),
user: link({ required: true, target: 'user' }),
userAgent: string(),
},
});export const Account = model({
slug: 'account',
pluralSlug: 'accounts',
fields: {
accessToken: string(),
accessTokenExpiresAt: date(),
accountId: string({ required: true }),
idToken: string(),
password: string(),
providerId: string({ required: true }),
refreshToken: string(),
refreshTokenExpiresAt: date(),
scope: string(),
user: link({ required: true, target: 'user' }),
},
});export const Verification = model({
slug: 'verification',
pluralSlug: 'verifications',
fields: {
expiresAt: date({ required: true }),
identifier: string({ required: true }),
value: string({ required: true }),
},
});
```## Testing
Use the following command to run the test suite:
```
bun test
```