better-auth-firestore 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025, Slava Yultyyev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # better-auth-firestore
2
+
3
+ Firestore (Firebase Admin SDK) adapter for Better Auth. Drop-in replacement for the Auth.js/NextAuth Firebase adapter with matching data shape to ease migration.
4
+
5
+ - Better Auth guide: https://www.better-auth.com/docs/guides/create-a-db-adapter
6
+ - Auth.js Firebase adapter docs: https://authjs.dev/getting-started/adapters/firebase#installation
7
+ - Auth.js Firebase adapter source: https://github.com/nextauthjs/next-auth/tree/main/packages/adapter-firebase
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pnpm add @yultyyev/better-auth-firestore firebase-admin better-auth
13
+ ```
14
+
15
+ ## Quick start
16
+
17
+ ```ts
18
+ import { betterAuth } from "better-auth";
19
+ import { firestoreAdapter, initFirestore } from "@yultyyev/better-auth-firestore";
20
+ import { cert } from "firebase-admin/app";
21
+
22
+ const firestore = initFirestore({
23
+ credential: cert({
24
+ projectId: process.env.FIREBASE_PROJECT_ID!,
25
+ clientEmail: process.env.FIREBASE_CLIENT_EMAIL!,
26
+ privateKey: process.env.FIREBASE_PRIVATE_KEY!.replace(/\\n/g, "\n"),
27
+ }),
28
+ projectId: process.env.FIREBASE_PROJECT_ID!,
29
+ name: "better-auth",
30
+ });
31
+
32
+ export const auth = betterAuth({
33
+ // ... your Better Auth options
34
+ database: firestoreAdapter({
35
+ firestore,
36
+ namingStrategy: "default", // or "snake_case"
37
+ collections: {
38
+ // users: "users",
39
+ // sessions: "sessions",
40
+ // accounts: "accounts",
41
+ // verificationTokens: "verificationTokens",
42
+ },
43
+ }),
44
+ });
45
+ ```
46
+
47
+ ## Options
48
+
49
+ ```ts
50
+ firestoreAdapter({
51
+ firestore?: Firestore;
52
+ namingStrategy?: "default" | "snake_case";
53
+ collections?: { users?: string; sessions?: string; accounts?: string; verificationTokens?: string };
54
+ debugLogs?: boolean | DBAdapterDebugLogOption;
55
+ });
56
+ ```
57
+
58
+ **Default collection names:**
59
+ - `users`: "users"
60
+ - `sessions`: "sessions"
61
+ - `accounts`: "accounts"
62
+ - `verificationTokens`: "verification_tokens" (snake_case) or "verificationTokens" (default)
63
+
64
+ ## Migration from Auth.js/NextAuth
65
+
66
+ If you're migrating from the Auth.js Firebase adapter, you can use your existing collection names by overriding them:
67
+
68
+ ```ts
69
+ // If you were using Auth.js with custom collection names
70
+ firestoreAdapter({
71
+ firestore,
72
+ collections: {
73
+ accounts: "authjs_accounts", // or whatever name you were using
74
+ // ... other overrides
75
+ },
76
+ });
77
+ ```
78
+
79
+ The adapter maintains the same data shape, so your existing data will work without migration scripts.
80
+
81
+ ## Testing with Firestore Emulator
82
+
83
+ ```bash
84
+ # start emulator (example)
85
+ docker run -d --rm \
86
+ --name auth-firestore \
87
+ -p 8080:8080 \
88
+ google/cloud-sdk:emulators gcloud beta emulators firestore start \
89
+ --host-port=0.0.0.0:8080
90
+
91
+ export FIRESTORE_EMULATOR_HOST=localhost:8080
92
+ pnpm vitest run
93
+ ```
94
+
95
+ ## Build
96
+
97
+ ```bash
98
+ pnpm build
99
+ ```
100
+
101
+ ## License
102
+
103
+ MIT.
@@ -0,0 +1,8 @@
1
+ import { type DBAdapterDebugLogOption } from "better-auth/adapters";
2
+ import type { Firestore } from "firebase-admin/firestore";
3
+ import type { FirestoreAdapterConfig } from "./types";
4
+ export interface FirestoreAdapterOptions extends Omit<FirestoreAdapterConfig, "firestore"> {
5
+ firestore?: Firestore;
6
+ debugLogs?: DBAdapterDebugLogOption;
7
+ }
8
+ export declare const firestoreAdapter: (config?: FirestoreAdapterOptions | Firestore) => import("better-auth/adapters").AdapterFactory;