Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/fix-sys-user-unique-validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@objectstack/platform-objects': patch
---

Fix `sys_user` load failure after the validation-rule type trim (#1485)

#1485 trimmed the unenforceable validation-rule types (`unique`, `async`,
`custom`) from the `ValidationRuleSchema` discriminated union, but `sys_user`
still declared an `email_unique` rule with `type: 'unique'`. Loading the object
then threw a `ZodError` ("Invalid discriminator value … at validations[0].type"),
failing `platform-objects.test.ts` and turning `main` red.

The rule was redundant: `sys_user` already declares a unique index on `email`
(`indexes: [{ fields: ['email'], unique: true }]`), and the user table is
managed by better-auth which enforces email uniqueness at the source. Removed
the unenforceable validation rule; uniqueness remains enforced by the index.
No other object uses a trimmed validation type.
14 changes: 4 additions & 10 deletions packages/platform-objects/src/identity/sys-user.object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,8 @@ export const SysUser = ObjectSchema.create({
mru: true,
},

validations: [
{
name: 'email_unique',
type: 'unique',
severity: 'error',
message: 'Email must be unique',
fields: ['email'],
caseSensitive: false,
},
],
// Email uniqueness is enforced by the unique index above (and better-auth's
// managed user table). A declarative `unique` validation rule is intentionally
// not used — uniqueness needs a DB lookup, not a synchronous validation, so it
// is not one of the declarable validation-rule types.
});
Loading