@groton/authjs-firestore-adapter 1.0.1 → 1.0.4

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/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [1.0.4](https://github.com/groton-school/authjs/compare/firestore-adapter/1.0.3...firestore-adapter/1.0.4) (2026-11-23)
6
+
7
+ ### Bug Fixes
8
+
9
+ * undo over-zealous object clean-up ([e6a782c](https://github.com/groton-school/authjs/commit/e6a782c88f57f309bf0c8ad6d30a9aeb3999cf42))
10
+ ## [1.0.3](https://github.com/groton-school/authjs/compare/firestore-adapter/1.0.1...firestore-adapter/1.0.3) (2026-11-15)
11
+
12
+ ### Bug Fixes
13
+
14
+ * nullify undefined properties on creation, delete undefined properties on update ([9ce52cc](https://github.com/groton-school/authjs/commit/9ce52ccccc7be4bf6391bbbdc758391e377e8fed))
15
+ ## [1.0.2](https://github.com/groton-school/authjs/compare/firestore-adapter/1.0.1...firestore-adapter/1.0.2) (2026-11-15)
16
+
17
+ ### Bug Fixes
18
+
19
+ * nullify undefined properties on creation, delete undefined properties on update ([9ce52cc](https://github.com/groton-school/authjs/commit/9ce52ccccc7be4bf6391bbbdc758391e377e8fed))
5
20
  ## [1.0.1](https://github.com/groton-school/authjs/compare/firestore-adapter/1.0.0...firestore-adapter/1.0.1) (2026-11-15)
6
21
 
7
22
  ### Bug Fixes
@@ -1,12 +1,12 @@
1
1
  import { AdapterAccount, AdapterUser } from '@auth/core/adapters';
2
2
  import { Collection, CollectionOptions } from '@battis/lazy-firestore';
3
- export declare class AdapterAccountsCollection extends Collection<AdapterAccount> {
3
+ export declare class Accounts extends Collection<AdapterAccount> {
4
4
  static readonly DEFAULT: {
5
5
  path: string;
6
6
  };
7
7
  }
8
- export declare function AdapterAccounts({ path, ...options }?: CollectionOptions): {
9
- linkAccount: (data: AdapterAccount) => Promise<AdapterAccount | null>;
8
+ export declare function AccountsAdapter({ path, ...options }?: CollectionOptions): {
9
+ linkAccount: (account: AdapterAccount) => Promise<AdapterAccount | null>;
10
10
  getAccount: (providerAccountId: AdapterAccount['providerAccountId'], provider: AdapterAccount['provider']) => Promise<AdapterAccount | null>;
11
11
  getUserByAccount: ({ provider, providerAccountId }: Pick<AdapterAccount, 'provider' | 'providerAccountId'>) => Promise<AdapterUser | null>;
12
12
  unlinkAccount: (account: Pick<AdapterAccount, 'provider' | 'providerAccountId'>) => Promise<AdapterAccount | undefined>;
@@ -0,0 +1,44 @@
1
+ import { Collection } from '@battis/lazy-firestore';
2
+ import { requireUnique } from '@battis/lazy-firestore/directives/requireUnique';
3
+ import { users } from './Users.js';
4
+ export class Accounts extends Collection {
5
+ static DEFAULT = { path: 'accounts' };
6
+ }
7
+ export function AccountsAdapter({ path = Accounts.DEFAULT.path, ...options } = Accounts.DEFAULT) {
8
+ const accounts = new Accounts({ path, ...options });
9
+ async function getAccount(providerAccountId, provider) {
10
+ return requireUnique({
11
+ list: await accounts.list({
12
+ ...identify({ provider, providerAccountId }),
13
+ strict: false
14
+ }),
15
+ strict: false
16
+ }).data;
17
+ }
18
+ return {
19
+ linkAccount: async (account) => (await accounts.create({
20
+ ...identify(account),
21
+ data: account,
22
+ strict: false
23
+ })).data,
24
+ getAccount,
25
+ getUserByAccount: async ({ provider, providerAccountId }) => {
26
+ const account = await getAccount(providerAccountId, provider);
27
+ if (account) {
28
+ return (await users().read({ id: account.userId, strict: false })).data;
29
+ }
30
+ return null;
31
+ },
32
+ unlinkAccount: async (account) => (await accounts.delete({
33
+ ...identify(account),
34
+ strict: false
35
+ })).data ?? undefined
36
+ };
37
+ }
38
+ function identify({ provider, providerAccountId }) {
39
+ return {
40
+ query: (ref) => ref
41
+ .where('provider', '==', provider)
42
+ .where('providerAccountId', '==', providerAccountId)
43
+ };
44
+ }
@@ -1,8 +1,8 @@
1
1
  import { AdapterAuthenticator } from '@auth/core/adapters';
2
2
  import { CollectionOptions } from '@battis/lazy-firestore';
3
- export declare function AdapterAuthenticators({ path, ...options }?: CollectionOptions): {
3
+ export declare function AuthenticatorsAdapter({ path, ...options }?: CollectionOptions): {
4
+ createAuthenticator: (authenticator: AdapterAuthenticator) => Promise<AdapterAuthenticator>;
4
5
  getAuthenticator: (id: AdapterAuthenticator['credentialID']) => Promise<AdapterAuthenticator | null>;
5
- createAuthenticator: (data: AdapterAuthenticator) => Promise<AdapterAuthenticator>;
6
6
  listAuthenticatorsByUserId: (userId: AdapterAuthenticator['userId']) => Promise<AdapterAuthenticator[]>;
7
7
  updateAuthenticatorCounter: (credentialID: AdapterAuthenticator['credentialID'], newCounter: AdapterAuthenticator['counter']) => Promise<AdapterAuthenticator>;
8
8
  };
@@ -1,23 +1,23 @@
1
1
  import { Collection } from '@battis/lazy-firestore';
2
2
  import { DateConverter } from '@battis/lazy-firestore/converters/Date';
3
- class AdapterAuthenticatorsCollection extends Collection {
3
+ class Authenticators extends Collection {
4
4
  static DEFAULT = { path: 'authenticators' };
5
5
  constructor(options) {
6
6
  super({ ...options, converter: { expires: DateConverter } });
7
7
  }
8
8
  }
9
- export function AdapterAuthenticators({ path = AdapterAuthenticatorsCollection.DEFAULT.path, ...options } = AdapterAuthenticatorsCollection.DEFAULT) {
10
- const authenticators = new AdapterAuthenticatorsCollection({
9
+ export function AuthenticatorsAdapter({ path = Authenticators.DEFAULT.path, ...options } = Authenticators.DEFAULT) {
10
+ const authenticators = new Authenticators({
11
11
  path,
12
12
  ...options
13
13
  });
14
14
  return {
15
- getAuthenticator: async (id) => (await authenticators.read({ id, strict: false })).data,
16
- createAuthenticator: async (data) => (await authenticators.create({
17
- data,
18
- id: data.credentialID,
15
+ createAuthenticator: async (authenticator) => (await authenticators.create({
16
+ data: authenticator,
17
+ id: authenticator.credentialID,
19
18
  strict: true
20
19
  })).data,
20
+ getAuthenticator: async (id) => (await authenticators.read({ id, strict: false })).data,
21
21
  listAuthenticatorsByUserId: async (userId) => (await authenticators.list({
22
22
  query: (ref) => ref.where('userId', '==', userId)
23
23
  })).map((doc) => doc.data),
@@ -1,17 +1,17 @@
1
1
  import { AdapterSession } from '@auth/core/adapters';
2
2
  import { Collection, CollectionOptions } from '@battis/lazy-firestore';
3
- export declare class AdapterSessionsCollection extends Collection<AdapterSession> {
3
+ export declare class Sessions extends Collection<AdapterSession> {
4
4
  static readonly DEFAULT: {
5
5
  path: string;
6
6
  };
7
7
  constructor(options: CollectionOptions);
8
8
  }
9
- export declare function AdapterSessions({ path, ...options }?: CollectionOptions): {
10
- createSession: (data: AdapterSession) => Promise<AdapterSession>;
9
+ export declare function SessionsAdapter({ path, ...options }?: CollectionOptions): {
10
+ createSession: (session: AdapterSession) => Promise<AdapterSession>;
11
11
  getSessionAndUser: (id: string) => Promise<{
12
12
  session: AdapterSession;
13
13
  user: import("@auth/core/adapters").AdapterUser;
14
14
  } | null>;
15
- updateSession: (patch: Partial<AdapterSession> & Pick<AdapterSession, 'sessionToken'>) => Promise<AdapterSession | null>;
15
+ updateSession: (session: Partial<AdapterSession> & Pick<AdapterSession, 'sessionToken'>) => Promise<AdapterSession | null>;
16
16
  deleteSession: (id: string) => Promise<AdapterSession | null>;
17
17
  };
@@ -1,7 +1,7 @@
1
1
  import { Collection } from '@battis/lazy-firestore';
2
2
  import { DateConverter } from '@battis/lazy-firestore/converters/Date';
3
- import { users } from './AdapterUsers.js';
4
- export class AdapterSessionsCollection extends Collection {
3
+ import { users } from './Users.js';
4
+ export class Sessions extends Collection {
5
5
  static DEFAULT = { path: 'sessions' };
6
6
  constructor(options) {
7
7
  super({
@@ -10,14 +10,17 @@ export class AdapterSessionsCollection extends Collection {
10
10
  });
11
11
  }
12
12
  }
13
- export function AdapterSessions({ path = AdapterSessionsCollection.DEFAULT.path, ...options } = AdapterSessionsCollection.DEFAULT) {
14
- const sessions = new AdapterSessionsCollection({ path, ...options });
13
+ export function SessionsAdapter({ path = Sessions.DEFAULT.path, ...options } = Sessions.DEFAULT) {
14
+ const sessions = new Sessions({ path, ...options });
15
15
  return {
16
- createSession: async (data) => (await sessions.create({
17
- id: data.sessionToken,
18
- data,
19
- strict: true
20
- })).data,
16
+ createSession: async (session) => {
17
+ console.log(JSON.stringify({ session }, null, 2));
18
+ return (await sessions.create({
19
+ id: session.sessionToken,
20
+ data: session,
21
+ strict: true
22
+ })).data;
23
+ },
21
24
  getSessionAndUser: async (id) => {
22
25
  const session = (await sessions.read({
23
26
  id,
@@ -32,9 +35,9 @@ export function AdapterSessions({ path = AdapterSessionsCollection.DEFAULT.path,
32
35
  }
33
36
  return null;
34
37
  },
35
- updateSession: async (patch) => (await sessions.update({
36
- id: patch.sessionToken,
37
- patch,
38
+ updateSession: async (session) => (await sessions.update({
39
+ id: session.sessionToken,
40
+ patch: session,
38
41
  strict: false
39
42
  })).data,
40
43
  deleteSession: async (id) => (await sessions.delete({
@@ -1,16 +1,16 @@
1
1
  import { AdapterUser } from '@auth/core/adapters';
2
2
  import { Collection, CollectionOptions } from '@battis/lazy-firestore';
3
- export declare class AdapterUsersCollection extends Collection<AdapterUser> {
3
+ export declare class Users extends Collection<AdapterUser> {
4
4
  static readonly DEFAULT: {
5
5
  path: string;
6
6
  };
7
7
  constructor(options: CollectionOptions);
8
8
  }
9
- export declare function users(): AdapterUsersCollection;
10
- export declare function AdapterUsers({ path, ...options }?: CollectionOptions): {
11
- createUser: (data: AdapterUser) => Promise<AdapterUser>;
9
+ export declare function users(): Users;
10
+ export declare function UsersAdapter({ path, ...options }?: CollectionOptions): {
11
+ createUser: (user: AdapterUser) => Promise<AdapterUser>;
12
12
  getUser: (id: string) => Promise<AdapterUser | null>;
13
13
  getUserByEmail: (email: string) => Promise<AdapterUser | null>;
14
- updateUser: (patch: Partial<AdapterUser> & Pick<AdapterUser, 'id'>) => Promise<AdapterUser>;
14
+ updateUser: (user: Partial<AdapterUser> & Pick<AdapterUser, 'id'>) => Promise<AdapterUser>;
15
15
  deleteUser: (id: string) => Promise<AdapterUser | null>;
16
16
  };
@@ -1,6 +1,6 @@
1
1
  import { Collection } from '@battis/lazy-firestore';
2
2
  import { requireUnique } from '@battis/lazy-firestore/directives/requireUnique';
3
- export class AdapterUsersCollection extends Collection {
3
+ export class Users extends Collection {
4
4
  static DEFAULT = { path: 'users' };
5
5
  constructor(options) {
6
6
  super({
@@ -21,29 +21,33 @@ export function users() {
21
21
  }
22
22
  throw new Error('Users collection not initialized');
23
23
  }
24
- export function AdapterUsers({ path = AdapterUsersCollection.DEFAULT.path, ...options } = AdapterUsersCollection.DEFAULT) {
25
- _users = new AdapterUsersCollection({ path, ...options });
24
+ export function UsersAdapter({ path = Users.DEFAULT.path, ...options } = Users.DEFAULT) {
25
+ _users = new Users({ path, ...options });
26
26
  return {
27
- createUser: async (data) => (await users().create({
28
- data,
29
- id: data.id,
30
- query: (ref) => ref.where('email', '==', data.email),
27
+ createUser: async (user) => (await users().create({
28
+ data: user,
29
+ id: user.id,
30
+ query: (ref) => ref.where('email', '==', user.email),
31
31
  strict: true
32
32
  })).data,
33
- getUser: async (id) => (await users().read({
34
- id,
35
- strict: false
36
- })).data,
37
- getUserByEmail: async (email) => requireUnique({
38
- list: await users().list({
39
- query: (ref) => ref.where('email', '==', email),
33
+ getUser: async (id) => {
34
+ return (await users().read({
35
+ id,
40
36
  strict: false
41
- }),
42
- strict: false
43
- }).data,
44
- updateUser: async (patch) => (await users().update({
45
- id: patch.id,
46
- patch,
37
+ })).data;
38
+ },
39
+ getUserByEmail: async (email) => {
40
+ return requireUnique({
41
+ list: await users().list({
42
+ query: (ref) => ref.where('email', '==', email),
43
+ strict: false
44
+ }),
45
+ strict: false
46
+ }).data;
47
+ },
48
+ updateUser: async (user) => (await users().update({
49
+ id: user.id,
50
+ patch: user,
47
51
  strict: true
48
52
  })).data,
49
53
  deleteUser: async (id) => (await users().delete({
@@ -1,12 +1,12 @@
1
1
  import { VerificationToken } from '@auth/core/adapters';
2
2
  import { Collection, CollectionOptions } from '@battis/lazy-firestore';
3
- export declare class VerificationTokensCollection extends Collection<VerificationToken> {
3
+ export declare class VerificationTokens extends Collection<VerificationToken> {
4
4
  static readonly DEFAULT: {
5
5
  path: string;
6
6
  };
7
7
  constructor(options: CollectionOptions);
8
8
  }
9
- export declare function VerificationTokens({ path, ...options }?: CollectionOptions): {
10
- createVerificationToken: (data: VerificationToken) => Promise<VerificationToken | null>;
9
+ export declare function VerificationTokensAdapter({ path, ...options }?: CollectionOptions): {
10
+ createVerificationToken: (token: VerificationToken) => Promise<VerificationToken | null>;
11
11
  useVerificationToken: (token: Pick<VerificationToken, 'identifier' | 'token'>) => Promise<VerificationToken | null>;
12
12
  };
@@ -1,15 +1,19 @@
1
1
  import { Collection } from '@battis/lazy-firestore';
2
2
  import { DateConverter } from '@battis/lazy-firestore/converters/Date';
3
- export class VerificationTokensCollection extends Collection {
3
+ export class VerificationTokens extends Collection {
4
4
  static DEFAULT = { path: 'verificationTokens' };
5
5
  constructor(options) {
6
6
  super({ ...options, converter: { expires: DateConverter } });
7
7
  }
8
8
  }
9
- export function VerificationTokens({ path = VerificationTokensCollection.DEFAULT.path, ...options } = VerificationTokensCollection.DEFAULT) {
10
- const tokens = new VerificationTokensCollection({ path, ...options });
9
+ export function VerificationTokensAdapter({ path = VerificationTokens.DEFAULT.path, ...options } = VerificationTokens.DEFAULT) {
10
+ const tokens = new VerificationTokens({ path, ...options });
11
11
  return {
12
- createVerificationToken: async (data) => (await tokens.create({ data, ...identify(data), strict: false })).data,
12
+ createVerificationToken: async (token) => (await tokens.create({
13
+ ...identify(token),
14
+ data: token,
15
+ strict: false
16
+ })).data,
13
17
  useVerificationToken: async (token) => (await tokens.delete({ ...identify(token), strict: false })).data
14
18
  };
15
19
  }
package/dist/index.js CHANGED
@@ -1,37 +1,37 @@
1
1
  import path from 'node:path';
2
2
  import { Firestore } from '@google-cloud/firestore';
3
- import { AdapterAccounts, AdapterAccountsCollection } from './AdapterAccounts.js';
4
- import { AdapterAuthenticators } from './AdapterAuthenticators.js';
5
- import { AdapterSessions, AdapterSessionsCollection } from './AdapterSessions.js';
6
- import { AdapterUsers, AdapterUsersCollection } from './AdapterUsers.js';
7
- import { VerificationTokens, VerificationTokensCollection } from './VerificationTokens.js';
3
+ import { Accounts, AccountsAdapter } from './Collections/Accounts.js';
4
+ import { AuthenticatorsAdapter } from './Collections/Authenticators.js';
5
+ import { Sessions, SessionsAdapter } from './Collections/Sessions.js';
6
+ import { Users, UsersAdapter } from './Collections/Users.js';
7
+ import { VerificationTokens, VerificationTokensAdapter } from './Collections/VerificationTokens.js';
8
8
  export function FirestoreAdapter({ db, databaseId, basePath = '.', usersPath, accountsPath, sessionsPath, verificationTokensPath, authenticatorsPath, firestore } = {}) {
9
9
  db = db || new Firestore({ databaseId, ...firestore });
10
10
  return {
11
- ...AdapterUsers({
11
+ ...UsersAdapter({
12
12
  db,
13
13
  path: path.join(
14
- /*turbopackIgnore: true*/ basePath, usersPath || AdapterUsersCollection.DEFAULT.path)
14
+ /*turbopackIgnore: true*/ basePath, usersPath || Users.DEFAULT.path)
15
15
  }),
16
- ...AdapterAccounts({
16
+ ...AccountsAdapter({
17
17
  db,
18
18
  path: path.join(
19
- /*turbopackIgnore: true*/ basePath, accountsPath || AdapterAccountsCollection.DEFAULT.path)
19
+ /*turbopackIgnore: true*/ basePath, accountsPath || Accounts.DEFAULT.path)
20
20
  }),
21
- ...AdapterSessions({
21
+ ...SessionsAdapter({
22
22
  db,
23
23
  path: path.join(
24
- /*turbopackIgnore: true*/ basePath, sessionsPath || AdapterSessionsCollection.DEFAULT.path)
24
+ /*turbopackIgnore: true*/ basePath, sessionsPath || Sessions.DEFAULT.path)
25
25
  }),
26
- ...VerificationTokens({
26
+ ...VerificationTokensAdapter({
27
27
  db,
28
28
  path: path.join(
29
- /*turbopackIgnore: true*/ basePath, verificationTokensPath || VerificationTokensCollection.DEFAULT.path)
29
+ /*turbopackIgnore: true*/ basePath, verificationTokensPath || VerificationTokens.DEFAULT.path)
30
30
  }),
31
- ...AdapterAuthenticators({
31
+ ...AuthenticatorsAdapter({
32
32
  db,
33
33
  path: path.join(
34
- /*turbopackIgnore: true*/ basePath, authenticatorsPath || AdapterAccountsCollection.DEFAULT.path)
34
+ /*turbopackIgnore: true*/ basePath, authenticatorsPath || Accounts.DEFAULT.path)
35
35
  })
36
36
  };
37
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@groton/authjs-firestore-adapter",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "homepage": "https://github.com/groton-school/authjs/tree/main/packages/firestore-adapter#readme",
5
5
  "repository": {
6
6
  "type": "github",
@@ -13,15 +13,18 @@
13
13
  },
14
14
  "type": "module",
15
15
  "exports": {
16
- ".": "./dist/index.js",
17
- "./collections/accounts": "./dist/AdapterAccounts.js",
18
- "./collections/users": "./dist/AdapterUsers.js",
19
- "./collections/sessions": "./dist/AdapterSessions.js",
20
- "./collections/authenticators": "./dist/AdapterAuthenticators.js"
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ },
20
+ "./collections/*": {
21
+ "types": "./dist/Collections/*.d.ts",
22
+ "default": "./dist/Collections/*.js"
23
+ },
24
+ "./package.json": "./package.json"
21
25
  },
22
- "types": "./dist/index.d.ts",
23
26
  "dependencies": {
24
- "@battis/lazy-firestore": "^1.0.0"
27
+ "@battis/lazy-firestore": "^1.1.0"
25
28
  },
26
29
  "devDependencies": {
27
30
  "@battis/workspace": "^0.0.12",
@@ -1,50 +0,0 @@
1
- import { Collection } from '@battis/lazy-firestore';
2
- import { requireUnique } from '@battis/lazy-firestore/directives/requireUnique';
3
- import { users } from './AdapterUsers.js';
4
- export class AdapterAccountsCollection extends Collection {
5
- static DEFAULT = { path: 'accounts' };
6
- }
7
- export function AdapterAccounts({ path = AdapterAccountsCollection.DEFAULT.path, ...options } = AdapterAccountsCollection.DEFAULT) {
8
- const accounts = new AdapterAccountsCollection({ path, ...options });
9
- const getAccount = async (providerAccountId, provider) => requireUnique({
10
- list: await accounts.list({
11
- ...identify({ provider, providerAccountId }),
12
- strict: false
13
- }),
14
- strict: false
15
- }).data;
16
- return {
17
- linkAccount: async (data) => (await accounts.create({
18
- ...identify(data),
19
- data,
20
- strict: false
21
- })).data,
22
- getAccount: async (providerAccountId, provider) => {
23
- return requireUnique({
24
- list: await accounts.list({
25
- ...identify({ provider, providerAccountId }),
26
- strict: false
27
- }),
28
- strict: false
29
- }).data;
30
- },
31
- getUserByAccount: async ({ provider, providerAccountId }) => {
32
- const account = await getAccount(provider, providerAccountId);
33
- if (account) {
34
- return (await users().read({ id: account.userId, strict: false })).data;
35
- }
36
- return null;
37
- },
38
- unlinkAccount: async (account) => (await accounts.delete({
39
- ...identify(account),
40
- strict: false
41
- })).data ?? undefined
42
- };
43
- }
44
- function identify({ provider, providerAccountId }) {
45
- return {
46
- query: (ref) => ref
47
- .where('provider', '==', provider)
48
- .where('providerAccountId', '==', providerAccountId)
49
- };
50
- }