Registry / auth-security / better-auth-effect

better-auth-effect

JSON →
library0.4.1jsnpmunverified

Better Auth database adapter for @effect/sql, version 0.4.1. Integrates Better Auth authentication with Effect SQL ecosystem, supporting PostgreSQL, MySQL, and SQLite via @effect/sql-pg, @effect/sql-mysql2, and @effect/sql-sqlite-node. Released as a thin adapter that accepts an Effect Runtime to share the connection pool, avoiding manual lifecycle management. Supports all Better Auth adapter operations (create, findOne, findMany, update, delete, etc.) and handles database dialect differences like RETURNING clauses. Requires Effect v3.15+, Better Auth v1.2+, and Node.js 20+.

npm install better-auth-effect
INSTALL
IMPORT
SIG · BETTER-AUTH-EFFECT
B
better-auth-effect
auth-securityjavascriptv0.4.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

effectSqlAdapter
import { effectSqlAdapter } from 'better-auth-effect'
const { effectSqlAdapter } = require('better-auth-effect')
Package is ESM-only since v0.1.0; require() will fail with ERR_MODULE_NOT_FOUND.
EffectSqlAdapterConfig
import type { EffectSqlAdapterConfig } from 'better-auth-effect'
import { EffectSqlAdapterConfig } from 'better-auth-effect'
This is a TypeScript type, not a runtime value. Use import type to avoid runtime errors.
default import
import effectSqlAdapter from 'better-auth-effect'
import { default as effectSqlAdapter } from 'better-auth-effect'
Package has both a default export (the adapter function) and a named export. The default export is the same as the named one.

Sets up Better Auth with Effect SQL PostgreSQL adapter using Runtime injection, showing layer composition and ManagedRuntime usage.

import { Effect, Layer, ManagedRuntime } from 'effect' import { SqlClient } from '@effect/sql' import { PgClient } from '@effect/sql-pg' import { betterAuth } from 'better-auth' import { effectSqlAdapter } from 'better-auth-effect' // Build the SQL layer const DatabaseLive = PgClient.layer({ url: 'postgresql://postgres:password@localhost:5432/myapp', }) // Build auth layer with adapter const AuthLive = Layer.scoped( Effect.Do.pipe( Effect.flatMap(() => Effect.runtime<SqlClient.SqlClient>()), Effect.map((rt) => betterAuth({ database: effectSqlAdapter({ runtime: rt, dialect: 'pg' }), }) ) ) ).pipe(Layer.provide(DatabaseLive)) // Run the application const runtime = ManagedRuntime.make(Layer.mergeAll(AuthLive, DatabaseLive)) // Use runtime to run effects with auth console.log('Auth adapter configured successfully')
Debug
Known issues
breakingPackage is ESM-only; require() throws ERR_MODULE_NOT_FOUND
fix
Use import or set type: module in package.json. For CommonJS projects, use dynamic import: const { effectSqlAdapter } = await import('better-auth-effect')
affects: >=0.1.0
gotchaRuntime must be obtained from Effect.runtime() inside a Layer or from ManagedRuntime, not created manually
fix
Use Effect.runtime<SqlClient>() inside a Layer or ManagedRuntime.make().runtime() to get the Runtime.
affects: >=0.1.0
gotchaMySQL dialect emulates RETURNING via LAST_INSERT_ID() + SELECT; requires id column as primary key on all tables
fix
Ensure all database tables (user, account, session, verification) have an id column with auto-increment primary key.
affects: >=0.1.0
deprecatedV0.3.x used a different configuration API; v0.4.0 introduced Runtime-based config
fix
Upgrade to v0.4+ and pass { runtime, dialect, debugLogs? } instead of previous SqlClient parameter.
affects: 0.3.x
Errors
Common errors & fixes
TypeError: effectSqlAdapter is not a function
Importing from wrong path or incorrect import style (e.g., require() in ESM package).
fix
Use import { effectSqlAdapter } from 'better-auth-effect' with native ESM.
Error: The runtime argument must be an Effect Runtime, got undefined
Runtime not provided or incorrectly extracted from Effect context.
fix
Ensure runtime is obtained via Effect.runtime<SqlClient>() inside a Layer.
Error: Dialect must be one of: 'pg', 'mysql', 'sqlite'
Invalid dialect string passed to effectSqlAdapter config.
fix
Use 'pg' for PostgreSQL, 'mysql' for MySQL, or 'sqlite' for SQLite.
Upgrade
Version history
0.4.1latest on npm
Audit
Dependencies
@effect/sqlrequiredPeer dependency: provides SqlClient abstraction for database operations.
better-authrequiredPeer dependency: core authentication library.
effectrequiredPeer dependency: provides Effect runtime and Layer system.
Agent activity
27 hits · last 30 days
node
22
OpenAI (training)
1
Resources
better-auth-effect — npm install better-auth-effect · libregistry