You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using cloudflare D1 database. Since they have a hard limit of 10GB data per database, I have to create different Databases for each live Tenant.
I have Key Value store (KV) which maps domain -> Database Name. So when a page (expect SignIn/Signup) are accessed, I need to know which database connect to dynamically.
As per docs, I need to export this from the src/auth.ts file:
const adapter = new DrizzleSQLiteAdapter(db, sessionTable, userTable);
So how to I handle this now? I can create a initilizeLucia function which will initialize based on the domain but that will create a new database adapter everytime.
import{Lucia}from"lucia";import{DrizzleSQLiteAdapter}from"@lucia-auth/adapter-drizzle";import{getClientDb,userTable,sessionTable}from"./db";exportasyncfunctioninitializeLucia(domain: string){constdb=awaitgetClientDb(domain);if(!db){thrownewError(`Unable to initialize database for domain: ${domain}`);}constadapter=newDrizzleSQLiteAdapter(db,sessionTable,userTable);returnnewLucia(adapter,{sessionCookie: {attributes: {secure: process.env.NODE_ENV==="production"}}});}// Extend the Lucia type definitionsdeclare module "lucia"{interfaceRegister{Lucia: ReturnType<typeofinitializeLucia>;DatabaseUserAttributes: {};}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm using cloudflare D1 database. Since they have a hard limit of 10GB data per database, I have to create different Databases for each live Tenant.
I have Key Value store (KV) which maps
domain
->Database Name
. So when a page (expect SignIn/Signup) are accessed, I need to know which database connect to dynamically.As per docs, I need to export this from the
src/auth.ts
file:const adapter = new DrizzleSQLiteAdapter(db, sessionTable, userTable);
So how to I handle this now? I can create a
initilizeLucia
function which will initialize based on the domain but that will create a new database adapter everytime.Is there a better way to do this?
Beta Was this translation helpful? Give feedback.
All reactions