-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsys-verification.object.ts
More file actions
95 lines (85 loc) · 3.08 KB
/
Copy pathsys-verification.object.ts
File metadata and controls
95 lines (85 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { ObjectSchema, Field } from '@objectstack/spec/data';
/**
* sys_verification — System Verification Object
*
* Email and phone verification token record.
* Backed by better-auth's `verification` model with ObjectStack field conventions.
*
* @namespace sys
*/
export const SysVerification = ObjectSchema.create({
name: 'sys_verification',
label: 'Verification',
pluralLabel: 'Verifications',
icon: 'shield-check',
isSystem: true,
managedBy: 'better-auth',
// [ADR-0066 D2/④] Secure-by-default: rows are LIVE one-time credentials
// (email/phone verification + password-reset tokens) — reading one is
// account takeover. Not covered by the wildcard `'*'` grant; admins retain
// access via the superuser bypass; better-auth reads via its adapter
// (system context), so verification flows are unaffected.
access: { default: 'private' },
// ADR-0010 §3.7 — managed by better-auth; tenants may not edit schema,
// but may add overlay row-level config. Use `no-overlay` if you need to
// forbid sys_metadata overlays entirely.
protection: {
lock: 'full',
reason: 'Identity table managed by better-auth — see ADR-0010.',
docsUrl: 'https://docs.objectstack.ai/adr/0010-metadata-protection',
},
description: 'Email and phone verification tokens',
titleFormat: 'Verification for {identifier}',
highlightFields: ['identifier', 'expires_at', 'created_at'],
fields: {
id: Field.text({
label: 'Verification ID',
required: true,
readonly: true,
}),
created_at: Field.datetime({
label: 'Created At',
defaultValue: 'NOW()',
readonly: true,
}),
updated_at: Field.datetime({
label: 'Updated At',
defaultValue: 'NOW()',
readonly: true,
}),
value: Field.text({
label: 'Verification Token',
required: true,
description: 'Token or code for verification',
}),
expires_at: Field.datetime({
label: 'Expires At',
required: true,
}),
identifier: Field.text({
label: 'Identifier',
required: true,
description: 'Email address or phone number',
}),
},
indexes: [
// `value` must NOT be unique. better-auth's oauth-provider stores OIDC
// authorization codes in this table with `value` = a JSON blob keyed by
// user+client+state, which can legitimately repeat. A UNIQUE constraint
// makes `/api/v1/auth/oauth2/authorize` fail (`UNIQUE constraint failed:
// sys_verification.value`) → 503, breaking cloud-as-IdP SSO entirely.
// better-auth keys verification lookups on `identifier`, not `value`.
{ fields: ['value'], unique: false },
{ fields: ['identifier'], unique: false },
{ fields: ['expires_at'], unique: false },
],
enable: {
trackHistory: false,
searchable: false,
apiEnabled: true,
// #1591 — reads only: writes are refused by the identity write guard
// (ADR-0092 D2) and owned by better-auth. HTTP answers 405 before the 403.
apiMethods: ['get'],
},
});