UNPKG

better-auth

Version:

The most comprehensive authentication framework for TypeScript.

26 lines (25 loc) 951 B
import { getAuthTables } from "@better-auth/core/db"; import { logger } from "@better-auth/core/env"; //#region src/db/adapter-base.ts async function getBaseAdapter(options, handleDirectDatabase) { let adapter; if (!options.database) { const tables = getAuthTables(options); const memoryDB = Object.keys(tables).reduce((acc, key) => { acc[key] = []; return acc; }, {}); const { memoryAdapter } = await import("@better-auth/memory-adapter"); adapter = memoryAdapter(memoryDB)(options); } else if (typeof options.database === "function") adapter = options.database(options); else adapter = await handleDirectDatabase(options); if (!adapter.transaction) { logger.warn("Adapter does not correctly implement transaction function, patching it automatically. Please update your adapter implementation."); adapter.transaction = async (cb) => { return cb(adapter); }; } return adapter; } //#endregion export { getBaseAdapter };