@objectstack/plugin-auth 2.0.2 → 2.0.5

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.
@@ -0,0 +1,97 @@
1
+ // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
2
+
3
+ import { ObjectSchema, Field } from '@objectstack/spec/data';
4
+
5
+ /**
6
+ * Auth User Object
7
+ *
8
+ * Uses better-auth's native schema for seamless migration:
9
+ * - id: string
10
+ * - createdAt: Date
11
+ * - updatedAt: Date
12
+ * - email: string (unique, lowercase)
13
+ * - emailVerified: boolean
14
+ * - name: string
15
+ * - image: string | null
16
+ */
17
+ export const AuthUser = ObjectSchema.create({
18
+ name: 'user',
19
+ label: 'User',
20
+ pluralLabel: 'Users',
21
+ icon: 'user',
22
+ description: 'User accounts for authentication',
23
+ titleFormat: '{name} ({email})',
24
+ compactLayout: ['name', 'email', 'emailVerified'],
25
+
26
+ fields: {
27
+ // ID is auto-generated by ObjectQL
28
+ id: Field.text({
29
+ label: 'User ID',
30
+ required: true,
31
+ readonly: true,
32
+ }),
33
+
34
+ createdAt: Field.datetime({
35
+ label: 'Created At',
36
+ defaultValue: 'NOW()',
37
+ readonly: true,
38
+ }),
39
+
40
+ updatedAt: Field.datetime({
41
+ label: 'Updated At',
42
+ defaultValue: 'NOW()',
43
+ readonly: true,
44
+ }),
45
+
46
+ email: Field.email({
47
+ label: 'Email',
48
+ required: true,
49
+ searchable: true,
50
+ }),
51
+
52
+ emailVerified: Field.boolean({
53
+ label: 'Email Verified',
54
+ defaultValue: false,
55
+ }),
56
+
57
+ name: Field.text({
58
+ label: 'Name',
59
+ required: true,
60
+ searchable: true,
61
+ maxLength: 255,
62
+ }),
63
+
64
+ image: Field.url({
65
+ label: 'Profile Image',
66
+ required: false,
67
+ }),
68
+ },
69
+
70
+ // Database indexes for performance
71
+ indexes: [
72
+ { fields: ['email'], unique: true },
73
+ { fields: ['createdAt'], unique: false },
74
+ ],
75
+
76
+ // Enable features
77
+ enable: {
78
+ trackHistory: true,
79
+ searchable: true,
80
+ apiEnabled: true,
81
+ apiMethods: ['get', 'list', 'create', 'update', 'delete'],
82
+ trash: true,
83
+ mru: true,
84
+ },
85
+
86
+ // Validation Rules
87
+ validations: [
88
+ {
89
+ name: 'email_unique',
90
+ type: 'unique',
91
+ severity: 'error',
92
+ message: 'Email must be unique',
93
+ fields: ['email'],
94
+ caseSensitive: false,
95
+ },
96
+ ],
97
+ });
@@ -0,0 +1,78 @@
1
+ // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
2
+
3
+ import { ObjectSchema, Field } from '@objectstack/spec/data';
4
+
5
+ /**
6
+ * Auth Verification Object
7
+ *
8
+ * Uses better-auth's native schema for seamless migration:
9
+ * - id: string
10
+ * - createdAt: Date
11
+ * - updatedAt: Date
12
+ * - value: string (verification token/code)
13
+ * - expiresAt: Date
14
+ * - identifier: string (email or phone number)
15
+ */
16
+ export const AuthVerification = ObjectSchema.create({
17
+ name: 'verification',
18
+ label: 'Verification',
19
+ pluralLabel: 'Verifications',
20
+ icon: 'shield-check',
21
+ description: 'Email and phone verification tokens',
22
+ titleFormat: 'Verification for {identifier}',
23
+ compactLayout: ['identifier', 'expiresAt', 'createdAt'],
24
+
25
+ fields: {
26
+ id: Field.text({
27
+ label: 'Verification ID',
28
+ required: true,
29
+ readonly: true,
30
+ }),
31
+
32
+ createdAt: Field.datetime({
33
+ label: 'Created At',
34
+ defaultValue: 'NOW()',
35
+ readonly: true,
36
+ }),
37
+
38
+ updatedAt: Field.datetime({
39
+ label: 'Updated At',
40
+ defaultValue: 'NOW()',
41
+ readonly: true,
42
+ }),
43
+
44
+ value: Field.text({
45
+ label: 'Verification Token',
46
+ required: true,
47
+ description: 'Token or code for verification',
48
+ }),
49
+
50
+ expiresAt: Field.datetime({
51
+ label: 'Expires At',
52
+ required: true,
53
+ }),
54
+
55
+ identifier: Field.text({
56
+ label: 'Identifier',
57
+ required: true,
58
+ description: 'Email address or phone number',
59
+ }),
60
+ },
61
+
62
+ // Database indexes for performance
63
+ indexes: [
64
+ { fields: ['value'], unique: true },
65
+ { fields: ['identifier'], unique: false },
66
+ { fields: ['expiresAt'], unique: false },
67
+ ],
68
+
69
+ // Enable features
70
+ enable: {
71
+ trackHistory: false,
72
+ searchable: false,
73
+ apiEnabled: true,
74
+ apiMethods: ['get', 'create', 'delete'], // No list or update
75
+ trash: false, // Hard delete expired tokens
76
+ mru: false,
77
+ },
78
+ });
@@ -0,0 +1,13 @@
1
+ // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
2
+
3
+ /**
4
+ * Auth Objects
5
+ *
6
+ * ObjectQL-based object definitions for authentication database schema.
7
+ * These objects replace the need for third-party ORMs like drizzle-orm.
8
+ */
9
+
10
+ export { AuthUser } from './auth-user.object.js';
11
+ export { AuthSession } from './auth-session.object.js';
12
+ export { AuthAccount } from './auth-account.object.js';
13
+ export { AuthVerification } from './auth-verification.object.js';