@lowdefy/plugin-better-auth 7.2.0 → 7.3.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.
@@ -21,7 +21,9 @@ async function InviteMember({ acting, auth, organizationId, properties }) {
21
21
  // appRoles, attributes, contactId and profile are registered invitation
22
22
  // additionalFields in the engine config; accepting the invitation
23
23
  // shallow-merges profile onto the user's profile bag (invitation wins per
24
- // key), sets contactId on the user row, and copies attributes and appRoles
24
+ // key), sets contactId on a login that has no link yet (an invitation naming
25
+ // a different contact than the login holds is refused), and copies
26
+ // attributes and appRoles
25
27
  // onto the minted member row. Each is declared without input: false
26
28
  // precisely so this body may carry it.
27
29
  const { appRoles, attributes, contactId, email, orgRole, profile, resend } = properties;
@@ -46,6 +48,11 @@ async function InviteMember({ acting, auth, organizationId, properties }) {
46
48
  if (!type.isNone(contactId) && !type.isString(contactId)) {
47
49
  throw new Error('InviteMember "contactId" is not a string.');
48
50
  }
51
+ // Accepting sets the link once, so an empty link would stick and refuse
52
+ // every later invitation that names a contact.
53
+ if (contactId === '') {
54
+ throw new Error('InviteMember "contactId" is an empty string.');
55
+ }
49
56
  // An omitted orgRole must still send something: createInvitation's body
50
57
  // schema declares role as required, so undefined fails the zod body, and ''
51
58
  // passes it silently - BetterAuth filters the empty entry out before
@@ -18,7 +18,6 @@
18
18
  // checked in, and rejecting it would break every non-self-service save from a
19
19
  // second admin surface.
20
20
  const allowedProperties = [
21
- 'contactId',
22
21
  'image',
23
22
  'name',
24
23
  'organizationId',
@@ -30,17 +29,18 @@ const allowedProperties = [
30
29
  // profile update is a shallow merge per top-level key onto the user's
31
30
  // existing bag - a key set to null is removed - so the row is read first;
32
31
  // the adapter's json additionalField transform handles storage on both ends.
33
- // name and image are the display copies. contactId is the link to the app's
34
- // canonical record for this person - a top-level field, so it is set outright
35
- // and never joins the profile merge. The step writes nothing else - not
36
- // email, not emailVerified, not attributes, not roles. Adapter-direct like
37
- // UpdateUserAttributes: fires NO user.update database hooks.
32
+ // name and image are the display copies. The step writes nothing else - not
33
+ // email, not emailVerified, not attributes, not roles, and not contactId: apps
34
+ // compare _user.contact_id in author and access checks, so the link is set only
35
+ // by accepting an invitation that carries it (createBeforeAcceptInvitationHook),
36
+ // never by a routine. Adapter-direct like UpdateUserAttributes: fires NO
37
+ // user.update database hooks.
38
38
  async function UpdateUserProfile({ auth, organizationId, properties }) {
39
- const { contactId, image, name, profile, userId } = properties;
39
+ const { image, name, profile, userId } = properties;
40
40
  const unknownProperties = Object.keys(properties).filter((key)=>!allowedProperties.includes(key));
41
41
  if (unknownProperties.length > 0) {
42
42
  const received = unknownProperties.map((key)=>`"${key}"`).join(', ');
43
- throw new Error(`UpdateUserProfile received unknown properties ${received}. ` + 'Allowed properties are "userId", "profile", "contactId", "name", "image", and "organizationId".');
43
+ throw new Error(`UpdateUserProfile received unknown properties ${received}. ` + 'Allowed properties are "userId", "profile", "name", "image", and "organizationId".');
44
44
  }
45
45
  if (type.isNone(userId)) {
46
46
  throw new Error('UpdateUserProfile requires a "userId" property.');
@@ -54,11 +54,8 @@ async function UpdateUserProfile({ auth, organizationId, properties }) {
54
54
  if (!type.isNone(image) && !type.isString(image)) {
55
55
  throw new Error('UpdateUserProfile "image" is not a string.');
56
56
  }
57
- if (!type.isNone(contactId) && !type.isString(contactId)) {
58
- throw new Error('UpdateUserProfile "contactId" is not a string.');
59
- }
60
- if (type.isNone(profile) && type.isNone(contactId) && type.isNone(name) && type.isNone(image)) {
61
- throw new Error('UpdateUserProfile requires at least one of "profile", "contactId", "name", or "image" to write.');
57
+ if (type.isNone(profile) && type.isNone(name) && type.isNone(image)) {
58
+ throw new Error('UpdateUserProfile requires at least one of "profile", "name", or "image" to write.');
62
59
  }
63
60
  const { adapter } = await auth.$context;
64
61
  const user = await adapter.findOne({
@@ -92,9 +89,6 @@ async function UpdateUserProfile({ auth, organizationId, properties }) {
92
89
  });
93
90
  update.profile = merged;
94
91
  }
95
- if (!type.isNone(contactId)) {
96
- update.contactId = contactId;
97
- }
98
92
  if (!type.isNone(name)) {
99
93
  update.name = name;
100
94
  }
@@ -151,12 +145,12 @@ async function UpdateUserProfile({ auth, organizationId, properties }) {
151
145
  // compared to the caller's own id, and when properties.userId is that id the
152
146
  // floor skips its check entirely - evaluated before the scope check, so a
153
147
  // person saves their own profile without any org authority and without holding
154
- // a member row in the organization the request names. Profile, contactId, name
155
- // and image are display, link and app data - no authorization check reads any
156
- // of them, so the exemption holds for contactId too. Targeting anyone else
157
- // writes the deployment-wide user row, so it needs user:update authority in an
158
- // organization the target holds a member row in - membership is the
159
- // relationship that makes that person the caller's business.
148
+ // a member row in the organization the request names. Profile, name and image
149
+ // are display and app data that no authorization check reads, which is what
150
+ // makes the exemption safe. Targeting anyone else writes the deployment-wide
151
+ // user row, so it needs user:update authority in an organization the target
152
+ // holds a member row in - membership is the relationship that makes that person
153
+ // the caller's business.
160
154
  UpdateUserProfile.meta = {
161
155
  authority: {
162
156
  scope: 'org',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/plugin-better-auth",
3
- "version": "7.2.0",
3
+ "version": "7.3.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy providers, API auth strategies, and admin steps for the BetterAuth engine.",
6
6
  "homepage": "https://lowdefy.com",
@@ -39,8 +39,8 @@
39
39
  "dist/*"
40
40
  ],
41
41
  "dependencies": {
42
- "@lowdefy/errors": "7.2.0",
43
- "@lowdefy/helpers": "7.2.0",
42
+ "@lowdefy/errors": "7.3.0",
43
+ "@lowdefy/helpers": "7.3.0",
44
44
  "better-auth": "1.7.7",
45
45
  "jose": "^6.2.3"
46
46
  },