{"_id":"@daveyplate/better-auth-instantdb","_rev":"8-dfc1dbeab6ad651e617cde5ff5252d1c","name":"@daveyplate/better-auth-instantdb","dist-tags":{"latest":"1.1.1"},"versions":{"1.0.0":{"name":"@daveyplate/better-auth-instantdb","version":"1.0.0","keywords":["typescript","instantdb","better","better-auth","auth","authentication","adapter","react","tanstack","next","nextjs"],"author":{"name":"daveycodez"},"license":"MIT","_id":"@daveyplate/better-auth-instantdb@1.0.0","maintainers":[{"name":"leakeddave","email":"leakeddave@me.com"}],"homepage":"https://github.com/daveyplate/better-auth-instantdb","dist":{"shasum":"a35df3947ad1a7ac2ad591dd1ed50d1dc04bb837","tarball":"https://registry.npmjs.org/@daveyplate/better-auth-instantdb/-/better-auth-instantdb-1.0.0.tgz","fileCount":12,"integrity":"sha512-40wie8gmytURYXLNDufaOBZ6YNE184tBMXcZg0tWIod75fF7J51Ph1Mznk3arRdOJzQo1UEJMFrWkaeG+Z5/+g==","signatures":[{"sig":"MEUCIQDgLLm5r22sGeyVQ2dJwXYLBuK44zqaoKAOo3zUYauBTQIgFkQ4awSMZFaZa4SqCZEfarUtvtaCtRMuZjOgRyUtBJs=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":46106},"types":"dist/index","module":"dist/index","exports":"./dist/index.js","gitHead":"a0c99754bcac60481d67266ffa576cbba7a81278","scripts":{"dev":"tsc-watch --onSuccess 'biome check --fix'","build":"tsup --clean --dts","prepublishOnly":"rm -rf dist && tsup --clean --dts"},"_npmUser":{"name":"leakeddave","email":"leakeddave@me.com"},"_npmVersion":"10.9.2","description":"Better Auth InstantDB Adapter","directories":{},"_nodeVersion":"23.11.0","_hasShrinkwrap":false,"packageManager":"pnpm@10.8.1","devDependencies":{"tsx":"^4.19.3","tsup":"^8.4.0","react":"^19.1.0","turbo":"^2.5.0","react-dom":"^19.1.0","tsc-watch":"^6.2.1","typescript":"^5.8.3","@types/node":"^22.14.1","better-auth":"^1.2.7","@types/react":"^19.1.2","@instantdb/admin":"^0.18.4","@instantdb/react":"^0.18.4","@types/react-dom":"^19.1.2","esbuild-plugin-preserve-directives":"^0.0.11"},"peerDependencies":{"react":">=18.0.0","react-dom":">=18.0.0","better-auth":">=1.2.6","@instantdb/admin":">=0.18.0","@instantdb/react":">=0.18.0"},"_npmOperationalInternal":{"tmp":"tmp/better-auth-instantdb_1.0.0_1744676939864_0.47021392251824756","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@daveyplate/better-auth-instantdb","version":"1.0.1","keywords":["typescript","instantdb","better","better-auth","auth","authentication","adapter","react","tanstack","next","nextjs"],"author":{"name":"daveycodez"},"license":"MIT","_id":"@daveyplate/better-auth-instantdb@1.0.1","maintainers":[{"name":"leakeddave","email":"leakeddave@me.com"}],"homepage":"https://github.com/daveyplate/better-auth-instantdb","dist":{"shasum":"62d42a7534e0c9469fc7159ca7e7a9a030d3991c","tarball":"https://registry.npmjs.org/@daveyplate/better-auth-instantdb/-/better-auth-instantdb-1.0.1.tgz","fileCount":12,"integrity":"sha512-fE9hgOxqAYCgBp+okPN5+FxPtHz3t4e4+ZtI1SQpHHUF8dW3vbUL/03liknc0VdIYGgkJEnjiBt11D58ydBuvQ==","signatures":[{"sig":"MEQCIAYOeWqueIaLPjKxZlrcs8skjkcM7oOTrWar9rVRsZJsAiBwrZdHo813NhhdXJoF4Q+FOAPUlCoYFCo+VOldxxxTPQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":46127},"types":"dist/index","module":"dist/index","exports":"./dist/index.js","gitHead":"99f52d9ab9510aa75a9899c35f47b197be8e3f5c","scripts":{"dev":"tsc-watch --onSuccess 'biome check --fix'","build":"tsup --clean --dts","prepublishOnly":"rm -rf dist && tsup --clean --dts"},"_npmUser":{"name":"leakeddave","email":"leakeddave@me.com"},"_npmVersion":"10.9.2","description":"Better Auth InstantDB Adapter","directories":{},"_nodeVersion":"23.11.0","_hasShrinkwrap":false,"packageManager":"pnpm@10.8.1","devDependencies":{"tsx":"^4.19.3","tsup":"^8.4.0","react":"^19.1.0","turbo":"^2.5.0","react-dom":"^19.1.0","tsc-watch":"^6.2.1","typescript":"^5.8.3","@types/node":"^22.14.1","better-auth":"^1.2.7","@types/react":"^19.1.2","@instantdb/admin":"^0.18.4","@instantdb/react":"^0.18.4","@types/react-dom":"^19.1.2","esbuild-plugin-preserve-directives":"^0.0.11"},"peerDependencies":{"react":">=18.0.0","react-dom":">=18.0.0","better-auth":">=1.2.6","@instantdb/admin":">=0.18.0","@instantdb/react":">=0.18.0"},"_npmOperationalInternal":{"tmp":"tmp/better-auth-instantdb_1.0.1_1744677110270_0.2892570701864896","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@daveyplate/better-auth-instantdb","version":"1.0.2","keywords":["typescript","instantdb","better","better-auth","auth","authentication","adapter","react","tanstack","next","nextjs"],"author":{"name":"daveycodez"},"license":"MIT","_id":"@daveyplate/better-auth-instantdb@1.0.2","maintainers":[{"name":"leakeddave","email":"leakeddave@me.com"}],"homepage":"https://github.com/daveyplate/better-auth-instantdb","dist":{"shasum":"321d7dabfc4e6aa8582a978fe441930848a75406","tarball":"https://registry.npmjs.org/@daveyplate/better-auth-instantdb/-/better-auth-instantdb-1.0.2.tgz","fileCount":12,"integrity":"sha512-XfK6JedcplVbfUqhmxT3k/F5xLKGuC7WpaMRGz/9+8XhxeJ/fydU/5DMNcheZu83VwLHquqdm1HSQImpYPC+rA==","signatures":[{"sig":"MEUCIDXl3+zltnY2yc2H7vBGwc/xWr4GTizWxznK80uhBDi2AiEAiAXshTHDzKH5FI1p5ckIjxdi47YO2cPGUHGAnJjAVSw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":46295},"types":"dist/index","module":"dist/index","exports":"./dist/index.js","gitHead":"f944bcb886d5561640a4139fa9251439807bdea5","scripts":{"dev":"tsc-watch --onSuccess 'biome check --fix'","build":"tsup --clean --dts","prepublishOnly":"rm -rf dist && tsup --clean --dts"},"_npmUser":{"name":"leakeddave","email":"leakeddave@me.com"},"_npmVersion":"10.9.2","description":"Better Auth InstantDB Adapter","directories":{},"_nodeVersion":"23.11.0","_hasShrinkwrap":false,"packageManager":"pnpm@10.8.1","devDependencies":{"tsx":"^4.19.3","tsup":"^8.4.0","react":"^19.1.0","turbo":"^2.5.0","react-dom":"^19.1.0","tsc-watch":"^6.2.1","typescript":"^5.8.3","@types/node":"^22.14.1","better-auth":"^1.2.7","@types/react":"^19.1.2","@instantdb/admin":"^0.18.4","@instantdb/react":"^0.18.4","@types/react-dom":"^19.1.2","esbuild-plugin-preserve-directives":"^0.0.11"},"peerDependencies":{"react":">=18.0.0","react-dom":">=18.0.0","better-auth":">=1.2.6","@instantdb/admin":">=0.18.0","@instantdb/react":">=0.18.0"},"_npmOperationalInternal":{"tmp":"tmp/better-auth-instantdb_1.0.2_1744698686023_0.23968495759278086","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@daveyplate/better-auth-instantdb","version":"1.0.3","keywords":["typescript","instantdb","better","better-auth","auth","authentication","adapter","react","tanstack","next","nextjs"],"author":{"name":"daveycodez"},"license":"MIT","_id":"@daveyplate/better-auth-instantdb@1.0.3","maintainers":[{"name":"leakeddave","email":"leakeddave@me.com"}],"homepage":"https://github.com/daveyplate/better-auth-instantdb","dist":{"shasum":"19c7a2191eb05c1c82a59e968dd1c25d913e0f13","tarball":"https://registry.npmjs.org/@daveyplate/better-auth-instantdb/-/better-auth-instantdb-1.0.3.tgz","fileCount":12,"integrity":"sha512-Hy1xdP/Hq+J8/04rLRDH+WcAE+f1ORIJSH4duFDydbevLbyWXf2c20f2RB3j3M2vIWgbV3I3YhUASUcqT+eWXQ==","signatures":[{"sig":"MEYCIQCfGzrFtZ7RkJqYAK1OyWI3bWEnDpCIXSizpXnRR6uhuwIhAIiIM91QfRrAvRjc/jtZz1EPxNB9gEZNIDmVQowQY6XI","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":46298},"types":"dist/index","module":"dist/index","exports":"./dist/index.js","gitHead":"55e8fc01cf549a0cee7179f818332660643ee8ca","scripts":{"dev":"tsc-watch --onSuccess 'biome check --fix'","build":"tsup --clean --dts","prepublishOnly":"rm -rf dist && tsup --clean --dts"},"_npmUser":{"name":"leakeddave","email":"leakeddave@me.com"},"_npmVersion":"10.9.2","description":"Better Auth InstantDB Adapter","directories":{},"_nodeVersion":"23.11.0","_hasShrinkwrap":false,"packageManager":"pnpm@10.8.1","devDependencies":{"tsx":"^4.19.3","tsup":"^8.4.0","react":"^19.1.0","turbo":"^2.5.0","react-dom":"^19.1.0","tsc-watch":"^6.2.1","typescript":"^5.8.3","@types/node":"^22.14.1","better-auth":"^1.2.7","@types/react":"^19.1.2","@instantdb/admin":"^0.18.4","@instantdb/react":"^0.18.4","@types/react-dom":"^19.1.2","esbuild-plugin-preserve-directives":"^0.0.11"},"peerDependencies":{"react":">=18.0.0","react-dom":">=18.0.0","better-auth":">=1.2.6","@instantdb/admin":">=0.18.0","@instantdb/react":">=0.18.0"},"_npmOperationalInternal":{"tmp":"tmp/better-auth-instantdb_1.0.3_1744698774456_0.6685918070812473","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"name":"@daveyplate/better-auth-instantdb","version":"1.0.4","keywords":["typescript","instantdb","better","better-auth","auth","authentication","adapter","react","tanstack","next","nextjs"],"author":{"name":"daveycodez"},"license":"MIT","_id":"@daveyplate/better-auth-instantdb@1.0.4","maintainers":[{"name":"leakeddave","email":"leakeddave@me.com"}],"homepage":"https://github.com/daveyplate/better-auth-instantdb","dist":{"shasum":"9036de1ea60876bcf4b6dc0d86035da6131c434f","tarball":"https://registry.npmjs.org/@daveyplate/better-auth-instantdb/-/better-auth-instantdb-1.0.4.tgz","fileCount":12,"integrity":"sha512-vKSyFrhLRAEFnOROLJK/daPHbdrQAOWFfBZrdxwmAloHXH830zpwAj3KrmKzKWuDtZvWHDRSu9XE4O24qW+JnQ==","signatures":[{"sig":"MEUCIQCZ1DptV+v2V86twG47lmmKf4dRwvjUWwab0/hMhouHJQIgEhJ40IK7Gikh6mPuQZAU11KPJPx47Y7WhpjbzLX727o=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":47776},"types":"dist/index","module":"dist/index","exports":"./dist/index.js","gitHead":"bf2ef54d43de36a49f54ce4bae88987950275270","scripts":{"dev":"tsc-watch --onSuccess 'biome check --fix'","build":"tsup --clean --dts","prepublishOnly":"rm -rf dist && tsup --clean --dts"},"_npmUser":{"name":"leakeddave","email":"leakeddave@me.com"},"_npmVersion":"10.9.2","description":"Better Auth InstantDB Adapter","directories":{},"_nodeVersion":"23.11.0","_hasShrinkwrap":false,"packageManager":"pnpm@10.8.1","devDependencies":{"tsx":"^4.19.3","tsup":"^8.4.0","react":"^19.1.0","turbo":"^2.5.0","react-dom":"^19.1.0","tsc-watch":"^6.2.1","typescript":"^5.8.3","@types/node":"^22.14.1","better-auth":"^1.2.7","@types/react":"^19.1.2","@instantdb/admin":"^0.18.4","@instantdb/react":"^0.18.4","@types/react-dom":"^19.1.2","esbuild-plugin-preserve-directives":"^0.0.11"},"peerDependencies":{"react":">=18.0.0","react-dom":">=18.0.0","better-auth":">=1.2.6","@instantdb/admin":">=0.18.0","@instantdb/react":">=0.18.0"},"_npmOperationalInternal":{"tmp":"tmp/better-auth-instantdb_1.0.4_1744746016592_0.6660940003917903","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@daveyplate/better-auth-instantdb","version":"1.1.0","keywords":["typescript","instantdb","better","better-auth","auth","authentication","adapter","react","tanstack","next","nextjs"],"author":{"name":"daveycodez"},"license":"MIT","_id":"@daveyplate/better-auth-instantdb@1.1.0","maintainers":[{"name":"leakeddave","email":"leakeddave@me.com"}],"homepage":"https://github.com/daveyplate/better-auth-instantdb","dist":{"shasum":"f6b47d21d8521ad497cbbb68bf7d73536264273b","tarball":"https://registry.npmjs.org/@daveyplate/better-auth-instantdb/-/better-auth-instantdb-1.1.0.tgz","fileCount":12,"integrity":"sha512-Y/sHB/etnSjcROGWPJQXqPaLwx3w1Svi+bTJ93you2XuA1hHwrcUDBQoJ0Qw+thjkdwdgePnCgHQFyDqBggvxw==","signatures":[{"sig":"MEYCIQD/KULWAbtgiri3Rpkrb+VIn2kali7v+D8Zrfm62vGf7wIhAPvwtjYIRPnmw5gkIADojEuiGXmnhUR1tdn+0RT/SYyb","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":58847},"types":"dist/index","module":"dist/index","exports":"./dist/index.js","gitHead":"e3087e4d2af9a56555f33b4b95418fa6327bba2e","scripts":{"dev":"tsc-watch --onSuccess 'biome check --fix'","build":"tsup --clean --dts","prepublishOnly":"rm -rf dist && tsup --clean --dts"},"_npmUser":{"name":"leakeddave","email":"leakeddave@me.com"},"_npmVersion":"10.9.2","description":"Better Auth InstantDB Adapter","directories":{},"_nodeVersion":"23.11.0","_hasShrinkwrap":false,"packageManager":"pnpm@10.8.1","devDependencies":{"tsx":"^4.19.3","tsup":"^8.4.0","react":"^19.1.0","turbo":"^2.5.0","react-dom":"^19.1.0","tsc-watch":"^6.2.1","typescript":"^5.8.3","@types/node":"^22.14.1","better-auth":"^1.2.7","@types/react":"^19.1.2","@instantdb/admin":"^0.18.4","@instantdb/react":"^0.18.4","@types/react-dom":"^19.1.2","esbuild-plugin-preserve-directives":"^0.0.11"},"peerDependencies":{"react":">=18.0.0","react-dom":">=18.0.0","better-auth":">=1.2.6","@instantdb/admin":">=0.18.0","@instantdb/react":">=0.18.0"},"_npmOperationalInternal":{"tmp":"tmp/better-auth-instantdb_1.1.0_1745102486274_0.027407683783623682","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"@daveyplate/better-auth-instantdb","version":"1.1.1","keywords":["typescript","instantdb","better","better-auth","auth","authentication","adapter","react","tanstack","next","nextjs"],"author":{"name":"daveycodez"},"license":"MIT","_id":"@daveyplate/better-auth-instantdb@1.1.1","maintainers":[{"name":"leakeddave","email":"leakeddave@me.com"}],"homepage":"https://github.com/daveyplate/better-auth-instantdb","dist":{"shasum":"5c27cf6a324c59ac0db79dd45719ea2ac328177a","tarball":"https://registry.npmjs.org/@daveyplate/better-auth-instantdb/-/better-auth-instantdb-1.1.1.tgz","fileCount":12,"integrity":"sha512-GeHQL5nPs7yUCtrWxc8E5ScvEppZQlgZ6bifaLbGmVg5GB9u5jfqMg4xBWlsisRm9Aa5iwVQtDNNFezVxX3HtA==","signatures":[{"sig":"MEYCIQDB6/4XZ1K7ZZ8oW9kvde57vvsxaxvr+wbg8zGiCIIlEgIhAIEwNJoIcjvZ32yqHGVCM4dt6Y6DYetnsv7aIfGh4V3A","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":56853},"types":"dist/index","module":"dist/index","exports":"./dist/index.js","gitHead":"4b4621614b9c6e843c001ba3f619def1ad3b60b8","scripts":{"dev":"tsc-watch --onSuccess 'biome check --fix'","build":"tsup --clean --dts","prepublishOnly":"rm -rf dist && tsup --clean --dts"},"_npmUser":{"name":"leakeddave","email":"leakeddave@me.com"},"_npmVersion":"10.9.2","description":"Better Auth InstantDB Adapter","directories":{},"_nodeVersion":"23.11.0","_hasShrinkwrap":false,"packageManager":"pnpm@10.8.1","devDependencies":{"tsx":"^4.19.3","tsup":"^8.4.0","react":"^19.1.0","turbo":"^2.5.0","react-dom":"^19.1.0","tsc-watch":"^6.2.1","typescript":"^5.8.3","@types/node":"^22.14.1","better-auth":"^1.2.7","@types/react":"^19.1.2","@instantdb/admin":"^0.18.4","@instantdb/react":"^0.18.4","@types/react-dom":"^19.1.2","esbuild-plugin-preserve-directives":"^0.0.11"},"peerDependencies":{"react":">=18.0.0","react-dom":">=18.0.0","better-auth":">=1.2.6","@instantdb/admin":">=0.18.0","@instantdb/react":">=0.18.0"},"_npmOperationalInternal":{"tmp":"tmp/better-auth-instantdb_1.1.1_1745103086431_0.8546432719607151","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2025-04-15T00:28:59.815Z","modified":"2025-11-21T03:13:00.175Z","1.0.0":"2025-04-15T00:29:00.056Z","1.0.1":"2025-04-15T00:31:50.450Z","1.0.2":"2025-04-15T06:31:26.258Z","1.0.3":"2025-04-15T06:32:54.635Z","1.0.4":"2025-04-15T19:40:16.791Z","1.1.0":"2025-04-19T22:41:26.452Z","1.1.1":"2025-04-19T22:51:26.604Z"},"author":{"name":"daveycodez"},"license":"MIT","homepage":"https://github.com/daveyplate/better-auth-instantdb","keywords":["typescript","instantdb","better","better-auth","auth","authentication","adapter","react","tanstack","next","nextjs"],"description":"Better Auth InstantDB Adapter","maintainers":[{"email":"leakeddave@me.com","name":"leakeddave"},{"email":"daveycodez@gmail.com","name":"daveycodez"}],"readme":"# Better Auth InstantDB Adapter\n\nA seamless integration between [Better Auth](https://better-auth.com) and [InstantDB](https://www.instantdb.com) that allows you to use InstantDB as your authentication database.\n\n[Better Auth UI Integration](https://better-auth-ui.com/data/instantdb)\n\n- *Own Your Auth*\n\n𝕏 [@daveycodez](https://x.com/daveycodez)\n\n☕️ [Buy me a coffee](https://buymeacoffee.com/daveycodez)\n\n## Installation\n\n```bash\npnpm add @daveyplate/better-auth-instantdb@latest\n```\n\n## Features\n\n- 🔐 **Complete Authentication**: Leverage Better Auth's authentication features with InstantDB as your database\n- 🔄 **Session Sync**: Automatically synchronize auth sessions between Better Auth and InstantDB\n- 🛠️ **Customizable**: Configure the adapter to match your specific needs\n- 🧩 **Type-Safe**: Fully typed with TypeScript for improved developer experience\n\n## Usage\n\n### Basic Setup\n\nFirst you need to add the InstantDB Adapter to your Better Auth config.\n\n#### auth.ts\n```typescript\nimport { betterAuth } from 'better-auth'\nimport { instantDBAdapter } from '@daveyplate/better-auth-instantdb'\nimport { init } from \"@instantdb/admin\";\nimport schema from \"instant.schema\";\n\n// Create InstantDB admin client\nconst adminDb = init({\n    appId: process.env.INSTANT_APP_ID,\n    apiKey: process.env.INSTANT_API_KEY\n    schema\n});\n\n// Create Better Auth instance with InstantDB adapter\nexport const auth = betterAuth({\n    database: instantDBAdapter({\n        db: adminDb,\n        usePlural: true, // Optional: set to true if your schema uses plural table names\n        debugLogs: false  // Optional: set to true to see detailed logs\n    }),\n    // Other Better Auth configuration options\n    emailAndPassword: { enabled: true }\n})\n```\n\n### Client-Side Usage\n\nSynchronize authentication state between Better Auth and InstantDB:\n\n#### providers.tsx\n```typescript\n\"use client\"\n\nimport { useSession } from '@/lib/auth-client'\nimport { init } from '@instantdb/react'\nimport { useInstantAuth } from '@daveyplate/better-auth-instantdb'\n\n// Initialize InstantDB client\nconst db = init({ \n    appId: process.env.NEXT_PUBLIC_INSTANT_APP_ID\n})\n\nexport function Providers({ children }) {\n    const { data: sessionData, isPending } = useSession()\n    \n    // Set up InstantDB auth sync with Better Auth\n    useInstantAuth({ \n        db, \n        sessionData,\n        isPending\n    })\n    \n    return (\n        // Your application code\n        {children}\n    )\n}\n```\n\n## InstantDB Schema and Permissions Setup\n\n⚠️ **Important**: You must manually create and configure the InstantDB schema and permissions files for this adapter to work correctly.\n\n### 1. Create Schema File\n\nCreate an `instant.schema.ts` file with the required entities for Better Auth:\n\n#### instant.schema.ts\n```typescript\nimport { i } from \"@instantdb/react\";\n\nconst _schema = i.schema({\n  entities: {\n    // System entities\n    $files: i.entity({\n      path: i.string().unique().indexed(),\n      url: i.any(),\n    }),\n    $users: i.entity({\n      email: i.string().unique().indexed(),\n    }),\n    // Authentication entities\n    users: i.entity({\n      createdAt: i.date(),\n      email: i.string().unique(),\n      emailVerified: i.boolean(),\n      image: i.string(),\n      name: i.string(),\n      updatedAt: i.date(),\n    }),\n    sessions: i.entity({\n      createdAt: i.date(),\n      expiresAt: i.date().indexed(),\n      ipAddress: i.string(),\n      token: i.string(),\n      updatedAt: i.date(),\n      userAgent: i.string(),\n      userId: i.string(),\n    }),\n    accounts: i.entity({\n      accessToken: i.string(),\n      accessTokenExpiresAt: i.date(),\n      accountId: i.string(),\n      createdAt: i.date(),\n      idToken: i.string(),\n      password: i.string(),\n      providerId: i.string(),\n      refreshToken: i.string(),\n      refreshTokenExpiresAt: i.date(),\n      scope: i.string(),\n      updatedAt: i.date(),\n      userId: i.string().indexed(),\n    }),\n    verifications: i.entity({\n      createdAt: i.date().indexed(),\n      expiresAt: i.date().indexed(),\n      identifier: i.string(),\n      updatedAt: i.date(),\n      value: i.string(),\n    }),\n    // Optional entities for additional features (public profile example)\n    profiles: i.entity({\n      createdAt: i.date(),\n      image: i.string(),\n      name: i.string(),\n      updatedAt: i.date(),\n    }),\n  },\n  links: {\n    // Required links for auth\n    users$user: {\n      forward: {\n        on: \"users\",\n        has: \"one\",\n        label: \"$user\",\n        onDelete: \"cascade\",\n      },\n      reverse: {\n        on: \"$users\",\n        has: \"one\",\n        label: \"user\",\n      },\n    },\n    sessionsUser: {\n      forward: {\n        on: \"sessions\",\n        has: \"one\",\n        label: \"user\",\n        onDelete: \"cascade\",\n      },\n      reverse: {\n        on: \"users\",\n        has: \"many\",\n        label: \"sessions\",\n      },\n    },\n    accountsUser: {\n      forward: {\n        on: \"accounts\",\n        has: \"one\",\n        label: \"user\",\n        onDelete: \"cascade\",\n      },\n      reverse: {\n        on: \"users\",\n        has: \"many\",\n        label: \"accounts\",\n      },\n    },\n    // Optional links (public profile example)\n    profilesUser: {\n      forward: {\n        on: \"profiles\",\n        has: \"one\",\n        label: \"user\",\n        onDelete: \"cascade\",\n      },\n      reverse: {\n        on: \"users\",\n        has: \"one\",\n        label: \"profile\",\n      },\n    },\n    // Add your custom links here\n  },\n});\n\n// This helps TypeScript display nicer intellisense\ntype _AppSchema = typeof _schema;\ninterface AppSchema extends _AppSchema {}\nconst schema: AppSchema = _schema;\n\nexport type { AppSchema };\nexport default schema;\n```\n\n### 2. Create Permissions File\n\nCreate an `instant.perms.ts` file to secure your schema:\n\n```typescript\n// instant.perms.ts\nimport type { InstantRules } from \"@instantdb/react\";\n\nconst rules = {\n  // Prevent creation of new attributes without explicit schema changes\n  attrs: {\n    allow: {\n      $default: \"false\",\n    },\n  },\n  // Auth entities permissions\n  users: {\n    bind: [\"isOwner\", \"auth.id != null && auth.id == data.id\"],\n    allow: {\n      view: \"isOwner\",\n      create: \"false\",\n      delete: \"false\",\n      update: \"isOwner && (newData.email == data.email) && (newData.emailVerified == data.emailVerified) && (newData.createdAt == data.createdAt)\",\n    },\n  },\n  accounts: {\n    bind: [\"isOwner\", \"auth.id != null && auth.id == data.userId\"],\n    allow: {\n      view: \"isOwner\",\n      create: \"false\",\n      delete: \"false\",\n      update: \"false\",\n    },\n  },\n  sessions: {\n    bind: [\"isOwner\", \"auth.id != null && auth.id == data.userId\"],\n    allow: {\n      view: \"isOwner\",\n      create: \"false\",\n      delete: \"false\",\n      update: \"false\",\n    },\n  },\n  verifications: {\n    allow: {\n      $default: \"false\"\n    }\n  },\n  // Optional permissions (public profile example)\n  profiles: {\n    bind: [\"isOwner\", \"auth.id != null && auth.id == data.id\"],\n    allow: {\n      view: \"true\",\n      create: \"false\",\n      delete: \"false\",\n      update: \"isOwner\",\n    },\n  },\n  // Add your custom entity permissions here\n} satisfies InstantRules;\n\nexport default rules;\n```\n\n### 3. Push Schema and Permissions to InstantDB\n\nAfter creating these files, use the InstantDB CLI to push them to your app:\n\n```bash\n# Push schema\nnpx instant-cli@latest push schema\n\n# Push permissions\nnpx instant-cli@latest push perms\n```\n\n### 4. Initialize InstantDB with Your Schema\n\nUpdate your client-side InstantDB initialization to use your schema:\n\n#### /database/instant.ts\n```typescript\nimport { init } from \"@instantdb/react\"\nimport schema from \"../../instant.schema\"\n\nexport const db = init({\n    appId: process.env.NEXT_PUBLIC_INSTANT_APP_ID,\n    schema\n})\n```\n\n## API Reference\n\n### `instantDBAdapter(options)`\n\nCreates an adapter that allows Better Auth to use InstantDB as its database.\n\n#### Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `db` | `InstantAdminDatabase` | (required) | An InstantDB admin client instance |\n| `usePlural` | `boolean` | `true` | Set to `false` if your schema uses singular table names |\n| `debugLogs` | `boolean` | `false` | Set to `true` to enable detailed logging |\n| `transactionHooks` | `Promise<TransactionChunk<any, any>[]>` | `undefined` | Custom hooks for create and update operations |\n\n### `useInstantAuth({ db, useSession })`\n\nA React hook that synchronizes authentication state between Better Auth and InstantDB.\n\n#### Parameters\n\n| Parameter | Type | Description |\n|-----------|------|-------------|\n| `db` | `InstantReactWebDatabase` | An InstantDB client instance |\n| `useSession` | `function` | The `useSession` hook from Better Auth |\n\n### `useInstantAuth({ db, sessionData, isPending })`\n\nAn alternative form of the React hook that synchronizes authentication state between Better Auth and InstantDB.\n\n#### Parameters\n\n| Parameter | Type | Description |\n|-----------|------|-------------|\n| `db` | `InstantReactWebDatabase` | An InstantDB client instance |\n| `sessionData` | `{ session: Session; user: User } \\| null` | Session data from Better Auth |\n| `isPending` | `boolean` | Whether the session data is still loading |\n\n## Advanced Usage\n\n### Custom Transaction Hooks\n\nYou can extend the adapter's behavior with custom transaction hooks:\n\n#### Sync public profile with user entity\n```typescript\ninstantDBAdapter({\n    db,\n    usePlural: true,\n    transactionHooks: {\n        create: async ({ model, data }) => {\n            if (model === \"users\") {\n                const transactions = [\n                    db.tx.profiles[data.id]\n                        .update({\n                            name: data.name,\n                            image: data.image,\n                            createdAt: Date.now(),\n                            updatedAt: Date.now()\n                        })\n                        .link({ user: data.id })\n                ]\n\n                return transactions\n            }\n        },\n        update: async ({ model, update, where }) => {\n            if (model === \"users\") {\n                const result = await db.query({ profiles: { $: { where: parseWhere(where) } } })\n\n                return result.profiles.map((profile) =>\n                    db.tx.profiles[profile.id].update({\n                        name: update.name,\n                        image: update.image,\n                        updatedAt: Date.now()\n                    })\n                )\n            }\n        }\n    }\n})\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md"}