Skip to content

Commit a14d703

Browse files
authored
Merge pull request #656 from objectstack-ai/copilot/fix-plugin-auth-field-names
2 parents ef22cf8 + 177e2dd commit a14d703

File tree

7 files changed

+87
-56
lines changed

7 files changed

+87
-56
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
import { defineStack } from '@objectstack/spec';
4+
import * as objects from './src/objects';
5+
6+
/**
7+
* ObjectStack Configuration for plugin-auth
8+
*
9+
* This configuration defines the authentication and identity kernel objects
10+
* for the ObjectStack platform.
11+
*/
12+
export default defineStack({
13+
manifest: {
14+
id: 'com.objectstack.plugin-auth',
15+
namespace: 'auth',
16+
version: '3.0.1',
17+
type: 'plugin',
18+
name: 'Authentication & Identity Plugin',
19+
description: 'Core authentication objects for ObjectStack (User, Session, Account, Verification)',
20+
},
21+
22+
// Export all authentication kernel objects
23+
objects: Object.values(objects),
24+
});

packages/plugins/plugin-auth/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@
77
"types": "dist/index.d.ts",
88
"scripts": {
99
"build": "tsup --config ../../../tsup.config.ts",
10-
"test": "vitest run"
10+
"test": "vitest run",
11+
"validate": "objectstack validate",
12+
"compile": "objectstack compile",
13+
"info": "objectstack info"
1114
},
1215
"dependencies": {
1316
"@objectstack/core": "workspace:*",
1417
"@objectstack/spec": "workspace:*",
1518
"better-auth": "^1.4.18"
1619
},
1720
"devDependencies": {
21+
"@objectstack/cli": "workspace:*",
1822
"@types/node": "^25.2.2",
1923
"typescript": "^5.0.0",
2024
"vitest": "^4.0.18"

packages/plugins/plugin-auth/src/objects/auth-account.object.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import { ObjectSchema, Field } from '@objectstack/spec/data';
77
*
88
* Uses better-auth's native schema for seamless migration:
99
* - id: string
10-
* - createdAt: Date
11-
* - updatedAt: Date
12-
* - providerId: string (e.g., 'google', 'github')
13-
* - accountId: string (provider's user ID)
14-
* - userId: string (link to user table)
15-
* - accessToken: string | null
16-
* - refreshToken: string | null
17-
* - idToken: string | null
18-
* - accessTokenExpiresAt: Date | null
19-
* - refreshTokenExpiresAt: Date | null
10+
* - created_at: Date
11+
* - updated_at: Date
12+
* - provider_id: string (e.g., 'google', 'github')
13+
* - account_id: string (provider's user ID)
14+
* - user_id: string (link to user table)
15+
* - access_token: string | null
16+
* - refresh_token: string | null
17+
* - id_token: string | null
18+
* - access_token_expires_at: Date | null
19+
* - refresh_token_expires_at: Date | null
2020
* - scope: string | null
2121
* - password: string | null (for email/password provider)
2222
*/
@@ -26,8 +26,8 @@ export const AuthAccount = ObjectSchema.create({
2626
pluralLabel: 'Accounts',
2727
icon: 'link',
2828
description: 'OAuth and authentication provider accounts',
29-
titleFormat: '{providerId} - {accountId}',
30-
compactLayout: ['providerId', 'userId', 'accountId'],
29+
titleFormat: '{provider_id} - {account_id}',
30+
compactLayout: ['provider_id', 'user_id', 'account_id'],
3131

3232
fields: {
3333
id: Field.text({
@@ -36,57 +36,57 @@ export const AuthAccount = ObjectSchema.create({
3636
readonly: true,
3737
}),
3838

39-
createdAt: Field.datetime({
39+
created_at: Field.datetime({
4040
label: 'Created At',
4141
defaultValue: 'NOW()',
4242
readonly: true,
4343
}),
4444

45-
updatedAt: Field.datetime({
45+
updated_at: Field.datetime({
4646
label: 'Updated At',
4747
defaultValue: 'NOW()',
4848
readonly: true,
4949
}),
5050

51-
providerId: Field.text({
51+
provider_id: Field.text({
5252
label: 'Provider ID',
5353
required: true,
5454
description: 'OAuth provider identifier (google, github, etc.)',
5555
}),
5656

57-
accountId: Field.text({
57+
account_id: Field.text({
5858
label: 'Provider Account ID',
5959
required: true,
6060
description: "User's ID in the provider's system",
6161
}),
6262

63-
userId: Field.text({
63+
user_id: Field.text({
6464
label: 'User ID',
6565
required: true,
6666
description: 'Link to user table',
6767
}),
6868

69-
accessToken: Field.textarea({
69+
access_token: Field.textarea({
7070
label: 'Access Token',
7171
required: false,
7272
}),
7373

74-
refreshToken: Field.textarea({
74+
refresh_token: Field.textarea({
7575
label: 'Refresh Token',
7676
required: false,
7777
}),
7878

79-
idToken: Field.textarea({
79+
id_token: Field.textarea({
8080
label: 'ID Token',
8181
required: false,
8282
}),
8383

84-
accessTokenExpiresAt: Field.datetime({
84+
access_token_expires_at: Field.datetime({
8585
label: 'Access Token Expires At',
8686
required: false,
8787
}),
8888

89-
refreshTokenExpiresAt: Field.datetime({
89+
refresh_token_expires_at: Field.datetime({
9090
label: 'Refresh Token Expires At',
9191
required: false,
9292
}),
@@ -105,8 +105,8 @@ export const AuthAccount = ObjectSchema.create({
105105

106106
// Database indexes for performance
107107
indexes: [
108-
{ fields: ['userId'], unique: false },
109-
{ fields: ['providerId', 'accountId'], unique: true },
108+
{ fields: ['user_id'], unique: false },
109+
{ fields: ['provider_id', 'account_id'], unique: true },
110110
],
111111

112112
// Enable features

packages/plugins/plugin-auth/src/objects/auth-session.object.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import { ObjectSchema, Field } from '@objectstack/spec/data';
77
*
88
* Uses better-auth's native schema for seamless migration:
99
* - id: string
10-
* - createdAt: Date
11-
* - updatedAt: Date
12-
* - userId: string
13-
* - expiresAt: Date
10+
* - created_at: Date
11+
* - updated_at: Date
12+
* - user_id: string
13+
* - expires_at: Date
1414
* - token: string
15-
* - ipAddress: string | null
16-
* - userAgent: string | null
15+
* - ip_address: string | null
16+
* - user_agent: string | null
1717
*/
1818
export const AuthSession = ObjectSchema.create({
1919
name: 'session',
@@ -22,7 +22,7 @@ export const AuthSession = ObjectSchema.create({
2222
icon: 'key',
2323
description: 'Active user sessions',
2424
titleFormat: 'Session {token}',
25-
compactLayout: ['userId', 'expiresAt', 'ipAddress'],
25+
compactLayout: ['user_id', 'expires_at', 'ip_address'],
2626

2727
fields: {
2828
id: Field.text({
@@ -31,24 +31,24 @@ export const AuthSession = ObjectSchema.create({
3131
readonly: true,
3232
}),
3333

34-
createdAt: Field.datetime({
34+
created_at: Field.datetime({
3535
label: 'Created At',
3636
defaultValue: 'NOW()',
3737
readonly: true,
3838
}),
3939

40-
updatedAt: Field.datetime({
40+
updated_at: Field.datetime({
4141
label: 'Updated At',
4242
defaultValue: 'NOW()',
4343
readonly: true,
4444
}),
4545

46-
userId: Field.text({
46+
user_id: Field.text({
4747
label: 'User ID',
4848
required: true,
4949
}),
5050

51-
expiresAt: Field.datetime({
51+
expires_at: Field.datetime({
5252
label: 'Expires At',
5353
required: true,
5454
}),
@@ -58,13 +58,13 @@ export const AuthSession = ObjectSchema.create({
5858
required: true,
5959
}),
6060

61-
ipAddress: Field.text({
61+
ip_address: Field.text({
6262
label: 'IP Address',
6363
required: false,
6464
maxLength: 45, // Support IPv6
6565
}),
6666

67-
userAgent: Field.textarea({
67+
user_agent: Field.textarea({
6868
label: 'User Agent',
6969
required: false,
7070
}),
@@ -73,8 +73,8 @@ export const AuthSession = ObjectSchema.create({
7373
// Database indexes for performance
7474
indexes: [
7575
{ fields: ['token'], unique: true },
76-
{ fields: ['userId'], unique: false },
77-
{ fields: ['expiresAt'], unique: false },
76+
{ fields: ['user_id'], unique: false },
77+
{ fields: ['expires_at'], unique: false },
7878
],
7979

8080
// Enable features

packages/plugins/plugin-auth/src/objects/auth-user.object.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { ObjectSchema, Field } from '@objectstack/spec/data';
77
*
88
* Uses better-auth's native schema for seamless migration:
99
* - id: string
10-
* - createdAt: Date
11-
* - updatedAt: Date
10+
* - created_at: Date
11+
* - updated_at: Date
1212
* - email: string (unique, lowercase)
13-
* - emailVerified: boolean
13+
* - email_verified: boolean
1414
* - name: string
1515
* - image: string | null
1616
*/
@@ -21,7 +21,7 @@ export const AuthUser = ObjectSchema.create({
2121
icon: 'user',
2222
description: 'User accounts for authentication',
2323
titleFormat: '{name} ({email})',
24-
compactLayout: ['name', 'email', 'emailVerified'],
24+
compactLayout: ['name', 'email', 'email_verified'],
2525

2626
fields: {
2727
// ID is auto-generated by ObjectQL
@@ -31,13 +31,13 @@ export const AuthUser = ObjectSchema.create({
3131
readonly: true,
3232
}),
3333

34-
createdAt: Field.datetime({
34+
created_at: Field.datetime({
3535
label: 'Created At',
3636
defaultValue: 'NOW()',
3737
readonly: true,
3838
}),
3939

40-
updatedAt: Field.datetime({
40+
updated_at: Field.datetime({
4141
label: 'Updated At',
4242
defaultValue: 'NOW()',
4343
readonly: true,
@@ -49,7 +49,7 @@ export const AuthUser = ObjectSchema.create({
4949
searchable: true,
5050
}),
5151

52-
emailVerified: Field.boolean({
52+
email_verified: Field.boolean({
5353
label: 'Email Verified',
5454
defaultValue: false,
5555
}),
@@ -70,7 +70,7 @@ export const AuthUser = ObjectSchema.create({
7070
// Database indexes for performance
7171
indexes: [
7272
{ fields: ['email'], unique: true },
73-
{ fields: ['createdAt'], unique: false },
73+
{ fields: ['created_at'], unique: false },
7474
],
7575

7676
// Enable features

packages/plugins/plugin-auth/src/objects/auth-verification.object.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { ObjectSchema, Field } from '@objectstack/spec/data';
77
*
88
* Uses better-auth's native schema for seamless migration:
99
* - id: string
10-
* - createdAt: Date
11-
* - updatedAt: Date
10+
* - created_at: Date
11+
* - updated_at: Date
1212
* - value: string (verification token/code)
13-
* - expiresAt: Date
13+
* - expires_at: Date
1414
* - identifier: string (email or phone number)
1515
*/
1616
export const AuthVerification = ObjectSchema.create({
@@ -20,7 +20,7 @@ export const AuthVerification = ObjectSchema.create({
2020
icon: 'shield-check',
2121
description: 'Email and phone verification tokens',
2222
titleFormat: 'Verification for {identifier}',
23-
compactLayout: ['identifier', 'expiresAt', 'createdAt'],
23+
compactLayout: ['identifier', 'expires_at', 'created_at'],
2424

2525
fields: {
2626
id: Field.text({
@@ -29,13 +29,13 @@ export const AuthVerification = ObjectSchema.create({
2929
readonly: true,
3030
}),
3131

32-
createdAt: Field.datetime({
32+
created_at: Field.datetime({
3333
label: 'Created At',
3434
defaultValue: 'NOW()',
3535
readonly: true,
3636
}),
3737

38-
updatedAt: Field.datetime({
38+
updated_at: Field.datetime({
3939
label: 'Updated At',
4040
defaultValue: 'NOW()',
4141
readonly: true,
@@ -47,7 +47,7 @@ export const AuthVerification = ObjectSchema.create({
4747
description: 'Token or code for verification',
4848
}),
4949

50-
expiresAt: Field.datetime({
50+
expires_at: Field.datetime({
5151
label: 'Expires At',
5252
required: true,
5353
}),
@@ -63,7 +63,7 @@ export const AuthVerification = ObjectSchema.create({
6363
indexes: [
6464
{ fields: ['value'], unique: true },
6565
{ fields: ['identifier'], unique: false },
66-
{ fields: ['expiresAt'], unique: false },
66+
{ fields: ['expires_at'], unique: false },
6767
],
6868

6969
// Enable features

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)