better-auth-firestore 1.1.2 → 1.1.3
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/README.md +37 -10
- package/dist/firebase-adapter.d.ts +2 -2
- package/dist/firebase-adapter.js +4 -7
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
**Firestore (Firebase Admin SDK) adapter for Better Auth.** A drop-in replacement for the Auth.js Firebase adapter with matching data shape.
|
|
10
10
|
|
|
11
11
|
- **Install:** `pnpm add better-auth-firestore firebase-admin better-auth`
|
|
12
|
-
- **Docs:** [Quickstart](#quick-start) • [Options](#options) • [Migration](#migration-from-authjsnextauth) • [Emulator](#
|
|
12
|
+
- **Docs:** [Quickstart](#quick-start) • [Options](#options) • [Migration](#migration-from-authjsnextauth) • [Emulator](#using-the-firestore-emulator)
|
|
13
13
|
- **Example:** See [`/examples/minimal`](./examples/minimal) for a complete Next.js App Router example
|
|
14
14
|
|
|
15
15
|
---
|
|
@@ -57,11 +57,11 @@ bun add better-auth-firestore firebase-admin better-auth
|
|
|
57
57
|
|
|
58
58
|
```ts
|
|
59
59
|
import { firestoreAdapter } from "better-auth-firestore";
|
|
60
|
-
import {
|
|
60
|
+
import { betterAuth } from "better-auth";
|
|
61
61
|
import { getFirestore } from "firebase-admin/firestore";
|
|
62
62
|
|
|
63
|
-
export const auth =
|
|
64
|
-
|
|
63
|
+
export const auth = betterAuth({
|
|
64
|
+
database: firestoreAdapter({ firestore: getFirestore() })
|
|
65
65
|
});
|
|
66
66
|
```
|
|
67
67
|
|
|
@@ -211,6 +211,17 @@ firestoreAdapter({
|
|
|
211
211
|
|
|
212
212
|
## Compatibility
|
|
213
213
|
|
|
214
|
+
### Better Auth versions
|
|
215
|
+
|
|
216
|
+
| Better Auth | Status | Notes |
|
|
217
|
+
|---|---|---|
|
|
218
|
+
| `^1.5.0` | ✅ Recommended | Uses the latest API and security fixes. |
|
|
219
|
+
| `^1.4.18` | ✅ Supported | Backward-compatible for existing projects. |
|
|
220
|
+
|
|
221
|
+
> **For older projects:** if your app still uses older Better Auth patterns (`createAuth` + `adapter`), this adapter remains compatible, but new projects should use `betterAuth` + `database`.
|
|
222
|
+
|
|
223
|
+
### Runtime compatibility
|
|
224
|
+
|
|
214
225
|
| Runtime | Supported | Notes |
|
|
215
226
|
|---|---|---|
|
|
216
227
|
| Node 18+ | ✅ | Recommended |
|
|
@@ -359,7 +370,7 @@ export const { GET, POST } = toNextJsHandler(auth);
|
|
|
359
370
|
|
|
360
371
|
```ts
|
|
361
372
|
import { firestoreAdapter } from "better-auth-firestore";
|
|
362
|
-
import {
|
|
373
|
+
import { betterAuth } from "better-auth";
|
|
363
374
|
import { initializeApp, cert } from "firebase-admin/app";
|
|
364
375
|
import { getFirestore } from "firebase-admin/firestore";
|
|
365
376
|
|
|
@@ -371,21 +382,37 @@ const app = initializeApp({
|
|
|
371
382
|
}),
|
|
372
383
|
});
|
|
373
384
|
|
|
374
|
-
export const auth =
|
|
375
|
-
|
|
385
|
+
export const auth = betterAuth({
|
|
386
|
+
database: firestoreAdapter({ firestore: getFirestore(app) }),
|
|
376
387
|
});
|
|
377
388
|
```
|
|
378
389
|
|
|
379
|
-
##
|
|
390
|
+
## Using the Firestore Emulator
|
|
391
|
+
|
|
392
|
+
The adapter fully supports the Firestore Emulator for both **local development** and **testing**. When `FIRESTORE_EMULATOR_HOST` is set, the Firebase Admin SDK automatically routes all requests to the emulator instead of production Firestore. Collection names remain unchanged — the adapter uses the same collections in emulator mode as in production.
|
|
393
|
+
|
|
394
|
+
### Local development
|
|
380
395
|
|
|
381
396
|
```bash
|
|
382
|
-
#
|
|
397
|
+
# 1. Start the emulator
|
|
383
398
|
docker run -d --rm \
|
|
384
399
|
--name auth-firestore \
|
|
385
400
|
-p 8080:8080 \
|
|
386
401
|
google/cloud-sdk:emulators gcloud beta emulators firestore start \
|
|
387
402
|
--host-port=0.0.0.0:8080
|
|
388
403
|
|
|
404
|
+
# 2. Set the env var and start your app
|
|
405
|
+
export FIRESTORE_EMULATOR_HOST=localhost:8080
|
|
406
|
+
pnpm run dev
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
Or add `FIRESTORE_EMULATOR_HOST=localhost:8080` to your `.env` file (supported by Next.js, Vite, etc.).
|
|
410
|
+
|
|
411
|
+
> **Note:** No credential or service account setup is needed when using the emulator — the Admin SDK skips authentication automatically.
|
|
412
|
+
|
|
413
|
+
### Running tests
|
|
414
|
+
|
|
415
|
+
```bash
|
|
389
416
|
export FIRESTORE_EMULATOR_HOST=localhost:8080
|
|
390
417
|
pnpm vitest run
|
|
391
418
|
```
|
|
@@ -406,7 +433,7 @@ privateKey: process.env.FIREBASE_PRIVATE_KEY!.replace(/\\n/g, "\n")
|
|
|
406
433
|
|
|
407
434
|
**Symptom:** Firebase Admin SDK requests hang or time out during local development.
|
|
408
435
|
|
|
409
|
-
**Fix:** Use the Firestore Emulator and set `FIRESTORE_EMULATOR_HOST=localhost:8080` before running your app. See [
|
|
436
|
+
**Fix:** Use the Firestore Emulator and set `FIRESTORE_EMULATOR_HOST=localhost:8080` before running your app. See [Using the Firestore Emulator](#using-the-firestore-emulator) for setup instructions.
|
|
410
437
|
|
|
411
438
|
### Error: Missing or insufficient permissions / Index required
|
|
412
439
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type DBAdapterDebugLogOption } from "better-auth/adapters";
|
|
1
|
+
import { createAdapterFactory, type DBAdapterDebugLogOption } from "better-auth/adapters";
|
|
2
2
|
import type { Firestore } from "firebase-admin/firestore";
|
|
3
3
|
import type { FirestoreAdapterConfig } from "./types";
|
|
4
4
|
export interface FirestoreAdapterOptions extends Omit<FirestoreAdapterConfig, "firestore"> {
|
|
5
5
|
firestore?: Firestore;
|
|
6
6
|
debugLogs?: DBAdapterDebugLogOption;
|
|
7
7
|
}
|
|
8
|
-
export declare const firestoreAdapter: (config?: FirestoreAdapterOptions | Firestore) =>
|
|
8
|
+
export declare const firestoreAdapter: (config?: FirestoreAdapterOptions | Firestore) => ReturnType<typeof createAdapterFactory>;
|
package/dist/firebase-adapter.js
CHANGED
|
@@ -33,15 +33,12 @@ function resolveDb(config) {
|
|
|
33
33
|
*/
|
|
34
34
|
function resolveCollectionNames(namingStrategy, overrides) {
|
|
35
35
|
const snake = namingStrategy === "snake_case";
|
|
36
|
-
// Only suffix collection names in test mode (when using emulator) to isolate test suites
|
|
37
|
-
const isTestMode = Boolean(process.env.FIRESTORE_EMULATOR_HOST);
|
|
38
|
-
const suffix = isTestMode ? (snake ? "_snake" : "_default") : "";
|
|
39
36
|
return {
|
|
40
|
-
users: overrides?.users ??
|
|
41
|
-
sessions: overrides?.sessions ??
|
|
42
|
-
accounts: overrides?.accounts ??
|
|
37
|
+
users: overrides?.users ?? "users",
|
|
38
|
+
sessions: overrides?.sessions ?? "sessions",
|
|
39
|
+
accounts: overrides?.accounts ?? "accounts",
|
|
43
40
|
verificationTokens: overrides?.verificationTokens ??
|
|
44
|
-
(snake ?
|
|
41
|
+
(snake ? "verification_tokens" : "verificationTokens"),
|
|
45
42
|
};
|
|
46
43
|
}
|
|
47
44
|
function convertTimestamp(value) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-auth-firestore",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Firestore adapter for Better Auth (Firebase Admin SDK)",
|
|
6
6
|
"author": "Slava Yultyyev <yultyyev@gmail.com>",
|
|
@@ -59,15 +59,15 @@
|
|
|
59
59
|
"typescript": "^5.0.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@biomejs/biome": "^2.
|
|
62
|
+
"@biomejs/biome": "^2.4.7",
|
|
63
63
|
"@semantic-release/changelog": "^6.0.3",
|
|
64
64
|
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
65
|
-
"@semantic-release/github": "^12.0.
|
|
66
|
-
"@semantic-release/npm": "^13.1.
|
|
65
|
+
"@semantic-release/github": "^12.0.6",
|
|
66
|
+
"@semantic-release/npm": "^13.1.5",
|
|
67
67
|
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
68
|
-
"rimraf": "^6.1.
|
|
69
|
-
"semantic-release": "^25.0.
|
|
68
|
+
"rimraf": "^6.1.3",
|
|
69
|
+
"semantic-release": "^25.0.3",
|
|
70
70
|
"typescript": "^5.9.3",
|
|
71
|
-
"vitest": "^4.0
|
|
71
|
+
"vitest": "^4.1.0"
|
|
72
72
|
}
|
|
73
73
|
}
|