JSPM

  • Created
  • Published
  • Downloads 69
  • Score
    100M100P100Q101172F
  • License Apache-2.0

A Better Auth adapter for RONIN

Package Exports

  • blade-better-auth
  • blade-better-auth/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (blade-better-auth) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Better Auth + RONIN

tests code coverage install size

A Better Auth adapter for storing session data in RONIN with ease.

Usage

import { betterAuth } from 'better-auth';
import { ronin } from "blade-better-auth";

const auth = betterAuth({
  database: ronin(),
  // ...
});

Or if you want to use a custom client instance:

import { betterAuth } from 'better-auth';
import { ronin } from "blade-better-auth";
import { createSyntaxFactory } from 'blade-client';

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:

// schema/index.ts

import { blob, boolean, date, link, model, string } from 'blade/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 }),
    userId: 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(),
    userId: 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