@slotform/auth 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +26 -2
- package/dist/ability/index.d.ts +31 -0
- package/dist/ability/index.d.ts.map +1 -0
- package/dist/ability/index.js +64 -0
- package/dist/ability/index.js.map +1 -0
- package/dist/access.d.ts +19 -0
- package/dist/access.d.ts.map +1 -0
- package/dist/access.js +33 -0
- package/dist/access.js.map +1 -0
- package/dist/callback-stubs.d.ts +15 -0
- package/dist/callback-stubs.d.ts.map +1 -0
- package/dist/callback-stubs.js +28 -0
- package/dist/callback-stubs.js.map +1 -0
- package/dist/client.d.ts +38 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +37 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +190 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +451 -0
- package/dist/index.js.map +1 -0
- package/dist/infer.d.ts +31 -0
- package/dist/infer.d.ts.map +1 -0
- package/dist/infer.js +2 -0
- package/dist/infer.js.map +1 -0
- package/dist/schema/devices.d.ts +404 -0
- package/dist/schema/devices.d.ts.map +1 -0
- package/dist/schema/devices.js +45 -0
- package/dist/schema/devices.js.map +1 -0
- package/dist/schema/index.d.ts +679 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +94 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/oauth.d.ts +2062 -0
- package/dist/schema/oauth.d.ts.map +1 -0
- package/dist/schema/oauth.js +245 -0
- package/dist/schema/oauth.js.map +1 -0
- package/dist/schema/organization.d.ts +388 -0
- package/dist/schema/organization.d.ts.map +1 -0
- package/dist/schema/organization.js +75 -0
- package/dist/schema/organization.js.map +1 -0
- package/dist/schema/passkey.d.ts +215 -0
- package/dist/schema/passkey.d.ts.map +1 -0
- package/dist/schema/passkey.js +29 -0
- package/dist/schema/passkey.js.map +1 -0
- package/dist/schema/sets.d.ts +3715 -0
- package/dist/schema/sets.d.ts.map +1 -0
- package/dist/schema/sets.js +48 -0
- package/dist/schema/sets.js.map +1 -0
- package/dist/scope.d.ts +36 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +59 -0
- package/dist/scope.js.map +1 -0
- package/dist/screens-fixtures.d.ts +148 -0
- package/dist/screens-fixtures.d.ts.map +1 -0
- package/dist/screens-fixtures.js +122 -0
- package/dist/screens-fixtures.js.map +1 -0
- package/dist/screens-session.d.ts +4 -0
- package/dist/screens-session.d.ts.map +1 -0
- package/dist/screens-session.js +24 -0
- package/dist/screens-session.js.map +1 -0
- package/dist/screens.d.ts +3 -0
- package/dist/screens.d.ts.map +1 -0
- package/dist/screens.js +8 -0
- package/dist/screens.js.map +1 -0
- package/dist/serve.d.ts +3 -0
- package/dist/serve.d.ts.map +1 -0
- package/dist/serve.js +44 -0
- package/dist/serve.js.map +1 -0
- package/dist/types.d.ts +152 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +215 -0
- package/dist/types.js.map +1 -0
- package/dist/worker/callback-url.d.ts +6 -0
- package/dist/worker/callback-url.d.ts.map +1 -0
- package/dist/worker/callback-url.js +57 -0
- package/dist/worker/callback-url.js.map +1 -0
- package/dist/worker/cimd-transport.d.ts +2 -0
- package/dist/worker/cimd-transport.d.ts.map +1 -0
- package/dist/worker/cimd-transport.js +86 -0
- package/dist/worker/cimd-transport.js.map +1 -0
- package/dist/worker/devices.d.ts +6 -0
- package/dist/worker/devices.d.ts.map +1 -0
- package/dist/worker/devices.js +70 -0
- package/dist/worker/devices.js.map +1 -0
- package/dist/worker/email-key.d.ts +2 -0
- package/dist/worker/email-key.d.ts.map +1 -0
- package/dist/worker/email-key.js +20 -0
- package/dist/worker/email-key.js.map +1 -0
- package/dist/worker/index.d.ts +156 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +507 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/listener.d.ts +12 -0
- package/dist/worker/listener.d.ts.map +1 -0
- package/dist/worker/listener.js +37 -0
- package/dist/worker/listener.js.map +1 -0
- package/dist/worker/oauth.d.ts +95 -0
- package/dist/worker/oauth.d.ts.map +1 -0
- package/dist/worker/oauth.js +456 -0
- package/dist/worker/oauth.js.map +1 -0
- package/dist/worker/outputs.d.ts +75 -0
- package/dist/worker/outputs.d.ts.map +1 -0
- package/dist/worker/outputs.js +7 -0
- package/dist/worker/outputs.js.map +1 -0
- package/dist/worker/procedures.d.ts +360 -0
- package/dist/worker/procedures.d.ts.map +1 -0
- package/dist/worker/procedures.js +464 -0
- package/dist/worker/procedures.js.map +1 -0
- package/dist/worker/rate-limit.d.ts +7 -0
- package/dist/worker/rate-limit.d.ts.map +1 -0
- package/dist/worker/rate-limit.js +49 -0
- package/dist/worker/rate-limit.js.map +1 -0
- package/dist/worker/reserved-slugs.d.ts +4 -0
- package/dist/worker/reserved-slugs.d.ts.map +1 -0
- package/dist/worker/reserved-slugs.js +30 -0
- package/dist/worker/reserved-slugs.js.map +1 -0
- package/dist/worker/session-ended.d.ts +6 -0
- package/dist/worker/session-ended.d.ts.map +1 -0
- package/dist/worker/session-ended.js +10 -0
- package/dist/worker/session-ended.js.map +1 -0
- package/dist/worker/sign-up-policy.d.ts +20 -0
- package/dist/worker/sign-up-policy.d.ts.map +1 -0
- package/dist/worker/sign-up-policy.js +65 -0
- package/dist/worker/sign-up-policy.js.map +1 -0
- package/dist/worker/tenancy.d.ts +23 -0
- package/dist/worker/tenancy.d.ts.map +1 -0
- package/dist/worker/tenancy.js +133 -0
- package/dist/worker/tenancy.js.map +1 -0
- package/guide/abilities.md +55 -0
- package/guide/add-a-role.md +33 -0
- package/guide/callbacks.md +97 -0
- package/guide/config.md +84 -0
- package/guide/devices.md +85 -0
- package/guide/mcp-oauth.md +97 -0
- package/guide/organizations.md +114 -0
- package/guide/protect-by-scope.md +29 -0
- package/guide/scopes.md +87 -0
- package/guide/sign-in.md +127 -0
- package/package.json +155 -3
- package/src/ability/index.ts +174 -0
- package/src/access.ts +45 -0
- package/src/callback-stubs.ts +45 -0
- package/src/client.ts +119 -0
- package/src/expo.tsx +275 -0
- package/src/index.ts +574 -0
- package/src/infer.ts +44 -0
- package/src/schema/devices.ts +54 -0
- package/src/schema/index.ts +128 -0
- package/src/schema/oauth.ts +320 -0
- package/src/schema/organization.ts +104 -0
- package/src/schema/passkey.ts +38 -0
- package/src/schema/sets.ts +73 -0
- package/src/scope.ts +135 -0
- package/src/screens-fixtures.ts +149 -0
- package/src/screens-session.ts +26 -0
- package/src/screens.ts +10 -0
- package/src/serve.ts +49 -0
- package/src/types.ts +313 -0
- package/src/worker/callback-url.ts +65 -0
- package/src/worker/cimd-transport.ts +115 -0
- package/src/worker/devices.ts +83 -0
- package/src/worker/email-key.ts +21 -0
- package/src/worker/index.ts +941 -0
- package/src/worker/listener.ts +55 -0
- package/src/worker/oauth.ts +709 -0
- package/src/worker/outputs.ts +102 -0
- package/src/worker/procedures.ts +758 -0
- package/src/worker/rate-limit.ts +64 -0
- package/src/worker/reserved-slugs.ts +39 -0
- package/src/worker/session-ended.ts +14 -0
- package/src/worker/sign-up-policy.ts +88 -0
- package/src/worker/tenancy.ts +229 -0
- package/templates/callbacks.ts +40 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// Better Auth's core identity tables (user / session / account / verification), as Drizzle SQLite tables.
|
|
2
|
+
// Schema tables: docs/architecture/plugins/auth.md, "Schema tables".
|
|
3
|
+
|
|
4
|
+
// Drizzle types the emitted declarations spell, named through `@slotform/db`: docs/architecture/plugins/auth.md, "Schema tables".
|
|
5
|
+
// biome-ignore lint/correctness/noUnusedImports: read by the declaration emit
|
|
6
|
+
import type {
|
|
7
|
+
Many,
|
|
8
|
+
One,
|
|
9
|
+
Relations,
|
|
10
|
+
SQLiteTableWithColumns,
|
|
11
|
+
} from "@slotform/db/orm";
|
|
12
|
+
import {
|
|
13
|
+
index,
|
|
14
|
+
integer,
|
|
15
|
+
relations,
|
|
16
|
+
sql,
|
|
17
|
+
sqliteTable,
|
|
18
|
+
text,
|
|
19
|
+
} from "@slotform/db/orm";
|
|
20
|
+
|
|
21
|
+
export const user = sqliteTable("user", {
|
|
22
|
+
id: text("id").primaryKey(),
|
|
23
|
+
name: text("name").notNull(),
|
|
24
|
+
email: text("email").notNull().unique(),
|
|
25
|
+
emailVerified: integer("email_verified", { mode: "boolean" })
|
|
26
|
+
.default(false)
|
|
27
|
+
.notNull(),
|
|
28
|
+
image: text("image"),
|
|
29
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
|
30
|
+
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
|
31
|
+
.notNull(),
|
|
32
|
+
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
|
|
33
|
+
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
|
34
|
+
.$onUpdate(() => new Date())
|
|
35
|
+
.notNull(),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const session = sqliteTable(
|
|
39
|
+
"session",
|
|
40
|
+
{
|
|
41
|
+
id: text("id").primaryKey(),
|
|
42
|
+
expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
|
|
43
|
+
token: text("token").notNull().unique(),
|
|
44
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
|
45
|
+
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
|
46
|
+
.notNull(),
|
|
47
|
+
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
|
|
48
|
+
.$onUpdate(() => new Date())
|
|
49
|
+
.notNull(),
|
|
50
|
+
ipAddress: text("ip_address"),
|
|
51
|
+
userAgent: text("user_agent"),
|
|
52
|
+
userId: text("user_id")
|
|
53
|
+
.notNull()
|
|
54
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
55
|
+
// Set by the organization plugin's active-organization session hooks;
|
|
56
|
+
// unused (always null) unless `organization` is enabled. No FK
|
|
57
|
+
// constraint — better-auth's own field def carries none either.
|
|
58
|
+
activeOrganizationId: text("active_organization_id"),
|
|
59
|
+
},
|
|
60
|
+
(table) => [index("session_userId_idx").on(table.userId)],
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
export const account = sqliteTable(
|
|
64
|
+
"account",
|
|
65
|
+
{
|
|
66
|
+
id: text("id").primaryKey(),
|
|
67
|
+
accountId: text("account_id").notNull(),
|
|
68
|
+
providerId: text("provider_id").notNull(),
|
|
69
|
+
userId: text("user_id")
|
|
70
|
+
.notNull()
|
|
71
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
72
|
+
accessToken: text("access_token"),
|
|
73
|
+
refreshToken: text("refresh_token"),
|
|
74
|
+
idToken: text("id_token"),
|
|
75
|
+
accessTokenExpiresAt: integer("access_token_expires_at", {
|
|
76
|
+
mode: "timestamp_ms",
|
|
77
|
+
}),
|
|
78
|
+
refreshTokenExpiresAt: integer("refresh_token_expires_at", {
|
|
79
|
+
mode: "timestamp_ms",
|
|
80
|
+
}),
|
|
81
|
+
scope: text("scope"),
|
|
82
|
+
password: text("password"),
|
|
83
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
|
84
|
+
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
|
85
|
+
.notNull(),
|
|
86
|
+
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
|
|
87
|
+
.$onUpdate(() => new Date())
|
|
88
|
+
.notNull(),
|
|
89
|
+
},
|
|
90
|
+
(table) => [index("account_userId_idx").on(table.userId)],
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
export const verification = sqliteTable(
|
|
94
|
+
"verification",
|
|
95
|
+
{
|
|
96
|
+
id: text("id").primaryKey(),
|
|
97
|
+
identifier: text("identifier").notNull(),
|
|
98
|
+
value: text("value").notNull(),
|
|
99
|
+
expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
|
|
100
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
|
101
|
+
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
|
102
|
+
.notNull(),
|
|
103
|
+
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
|
|
104
|
+
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
|
105
|
+
.$onUpdate(() => new Date())
|
|
106
|
+
.notNull(),
|
|
107
|
+
},
|
|
108
|
+
(table) => [index("verification_identifier_idx").on(table.identifier)],
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
export const userRelations = relations(user, ({ many }) => ({
|
|
112
|
+
sessions: many(session),
|
|
113
|
+
accounts: many(account),
|
|
114
|
+
}));
|
|
115
|
+
|
|
116
|
+
export const sessionRelations = relations(session, ({ one }) => ({
|
|
117
|
+
user: one(user, {
|
|
118
|
+
fields: [session.userId],
|
|
119
|
+
references: [user.id],
|
|
120
|
+
}),
|
|
121
|
+
}));
|
|
122
|
+
|
|
123
|
+
export const accountRelations = relations(account, ({ one }) => ({
|
|
124
|
+
user: one(user, {
|
|
125
|
+
fields: [account.userId],
|
|
126
|
+
references: [user.id],
|
|
127
|
+
}),
|
|
128
|
+
}));
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
// The OAuth provider's tables for MCP, with the `jwt` plugin's `jwks`, as Drizzle SQLite tables.
|
|
2
|
+
// Schema tables: docs/architecture/plugins/auth.md, "Schema tables".
|
|
3
|
+
|
|
4
|
+
// Drizzle types the emitted declarations spell, named through `@slotform/db`: docs/architecture/plugins/auth.md, "Schema tables".
|
|
5
|
+
// biome-ignore lint/correctness/noUnusedImports: read by the declaration emit
|
|
6
|
+
import type {
|
|
7
|
+
Many,
|
|
8
|
+
One,
|
|
9
|
+
Relations,
|
|
10
|
+
SQLiteTableWithColumns,
|
|
11
|
+
} from "@slotform/db/orm";
|
|
12
|
+
import {
|
|
13
|
+
index,
|
|
14
|
+
integer,
|
|
15
|
+
relations,
|
|
16
|
+
sqliteTable,
|
|
17
|
+
text,
|
|
18
|
+
uniqueIndex,
|
|
19
|
+
} from "@slotform/db/orm";
|
|
20
|
+
import { session, user } from "./index.ts";
|
|
21
|
+
|
|
22
|
+
// The scopes a consent, access token or refresh token row stores, as the list
|
|
23
|
+
// better-auth wrote.
|
|
24
|
+
export function scopesOf(stored: string): string[] {
|
|
25
|
+
const scopes: unknown = JSON.parse(stored);
|
|
26
|
+
if (
|
|
27
|
+
!Array.isArray(scopes) ||
|
|
28
|
+
!scopes.every((scope) => typeof scope === "string")
|
|
29
|
+
) {
|
|
30
|
+
throw new Error("Stored scopes are not a list of strings");
|
|
31
|
+
}
|
|
32
|
+
return scopes;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const jwks = sqliteTable("jwks", {
|
|
36
|
+
id: text("id").primaryKey(),
|
|
37
|
+
publicKey: text("public_key").notNull(),
|
|
38
|
+
privateKey: text("private_key").notNull(),
|
|
39
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull(),
|
|
40
|
+
expiresAt: integer("expires_at", { mode: "timestamp_ms" }),
|
|
41
|
+
alg: text("alg"),
|
|
42
|
+
crv: text("crv"),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export const oauthClient = sqliteTable(
|
|
46
|
+
"oauth_client",
|
|
47
|
+
{
|
|
48
|
+
id: text("id").primaryKey(),
|
|
49
|
+
clientId: text("client_id").notNull().unique(),
|
|
50
|
+
clientSecret: text("client_secret"),
|
|
51
|
+
clientDiscoveryId: text("client_discovery_id"),
|
|
52
|
+
disabled: integer("disabled", { mode: "boolean" }).default(false),
|
|
53
|
+
skipConsent: integer("skip_consent", { mode: "boolean" }),
|
|
54
|
+
enableEndSession: integer("enable_end_session", { mode: "boolean" }),
|
|
55
|
+
subjectType: text("subject_type"),
|
|
56
|
+
scopes: text("scopes"),
|
|
57
|
+
clientCredentialsScopes: text("client_credentials_scopes").default("[]"),
|
|
58
|
+
userId: text("user_id").references(() => user.id),
|
|
59
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" }),
|
|
60
|
+
updatedAt: integer("updated_at", { mode: "timestamp_ms" }),
|
|
61
|
+
name: text("name"),
|
|
62
|
+
uri: text("uri"),
|
|
63
|
+
icon: text("icon"),
|
|
64
|
+
contacts: text("contacts"),
|
|
65
|
+
tos: text("tos"),
|
|
66
|
+
policy: text("policy"),
|
|
67
|
+
softwareId: text("software_id"),
|
|
68
|
+
softwareVersion: text("software_version"),
|
|
69
|
+
softwareStatement: text("software_statement"),
|
|
70
|
+
redirectUris: text("redirect_uris").notNull(),
|
|
71
|
+
postLogoutRedirectUris: text("post_logout_redirect_uris"),
|
|
72
|
+
backchannelLogoutUri: text("backchannel_logout_uri"),
|
|
73
|
+
backchannelLogoutSessionRequired: integer(
|
|
74
|
+
"backchannel_logout_session_required",
|
|
75
|
+
{ mode: "boolean" },
|
|
76
|
+
),
|
|
77
|
+
tokenEndpointAuthMethod: text("token_endpoint_auth_method"),
|
|
78
|
+
applicationType: text("application_type"),
|
|
79
|
+
jwks: text("jwks"),
|
|
80
|
+
jwksUri: text("jwks_uri"),
|
|
81
|
+
grantTypes: text("grant_types"),
|
|
82
|
+
responseTypes: text("response_types"),
|
|
83
|
+
requirePKCE: integer("require_pkce", { mode: "boolean" }),
|
|
84
|
+
dpopBoundAccessTokens: integer("dpop_bound_access_tokens", {
|
|
85
|
+
mode: "boolean",
|
|
86
|
+
}).default(false),
|
|
87
|
+
referenceId: text("reference_id"),
|
|
88
|
+
metadata: text("metadata"),
|
|
89
|
+
},
|
|
90
|
+
(table) => [index("oauthClient_userId_idx").on(table.userId)],
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
export const oauthResource = sqliteTable("oauth_resource", {
|
|
94
|
+
id: text("id").primaryKey(),
|
|
95
|
+
identifier: text("identifier").notNull().unique(),
|
|
96
|
+
name: text("name").notNull(),
|
|
97
|
+
accessTokenTtl: integer("access_token_ttl"),
|
|
98
|
+
refreshTokenTtl: integer("refresh_token_ttl"),
|
|
99
|
+
signingAlgorithm: text("signing_algorithm"),
|
|
100
|
+
signingKeyId: text("signing_key_id"),
|
|
101
|
+
allowedScopes: text("allowed_scopes"),
|
|
102
|
+
customClaims: text("custom_claims"),
|
|
103
|
+
dpopBoundAccessTokensRequired: integer("dpop_bound_access_tokens_required", {
|
|
104
|
+
mode: "boolean",
|
|
105
|
+
}).default(false),
|
|
106
|
+
disabled: integer("disabled", { mode: "boolean" }).default(false),
|
|
107
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" }),
|
|
108
|
+
updatedAt: integer("updated_at", { mode: "timestamp_ms" }),
|
|
109
|
+
policyVersion: integer("policy_version").default(1),
|
|
110
|
+
metadata: text("metadata"),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
export const oauthClientResource = sqliteTable(
|
|
114
|
+
"oauth_client_resource",
|
|
115
|
+
{
|
|
116
|
+
id: text("id").primaryKey(),
|
|
117
|
+
clientId: text("client_id")
|
|
118
|
+
.notNull()
|
|
119
|
+
.references(() => oauthClient.clientId, { onDelete: "cascade" }),
|
|
120
|
+
resourceId: text("resource_id")
|
|
121
|
+
.notNull()
|
|
122
|
+
.references(() => oauthResource.identifier, { onDelete: "cascade" }),
|
|
123
|
+
metadata: text("metadata"),
|
|
124
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" }),
|
|
125
|
+
},
|
|
126
|
+
(table) => [
|
|
127
|
+
uniqueIndex("oauthClientResource_clientId_resourceId_uidx").on(
|
|
128
|
+
table.clientId,
|
|
129
|
+
table.resourceId,
|
|
130
|
+
),
|
|
131
|
+
index("oauthClientResource_clientId_idx").on(table.clientId),
|
|
132
|
+
index("oauthClientResource_resourceId_idx").on(table.resourceId),
|
|
133
|
+
],
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
export const oauthRefreshToken = sqliteTable(
|
|
137
|
+
"oauth_refresh_token",
|
|
138
|
+
{
|
|
139
|
+
id: text("id").primaryKey(),
|
|
140
|
+
token: text("token").notNull().unique(),
|
|
141
|
+
clientId: text("client_id")
|
|
142
|
+
.notNull()
|
|
143
|
+
.references(() => oauthClient.clientId),
|
|
144
|
+
sessionId: text("session_id").references(() => session.id, {
|
|
145
|
+
onDelete: "set null",
|
|
146
|
+
}),
|
|
147
|
+
userId: text("user_id")
|
|
148
|
+
.notNull()
|
|
149
|
+
.references(() => user.id),
|
|
150
|
+
referenceId: text("reference_id"),
|
|
151
|
+
authorizationCodeId: text("authorization_code_id"),
|
|
152
|
+
resources: text("resources"),
|
|
153
|
+
requestedUserInfoClaims: text("requested_user_info_claims"),
|
|
154
|
+
expiresAt: integer("expires_at", { mode: "timestamp_ms" }),
|
|
155
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" }),
|
|
156
|
+
revoked: integer("revoked", { mode: "timestamp_ms" }),
|
|
157
|
+
rotatedAt: integer("rotated_at", { mode: "timestamp_ms" }),
|
|
158
|
+
rotationReplayResponse: text("rotation_replay_response"),
|
|
159
|
+
rotationReplayExpiresAt: integer("rotation_replay_expires_at", {
|
|
160
|
+
mode: "timestamp_ms",
|
|
161
|
+
}),
|
|
162
|
+
authTime: integer("auth_time", { mode: "timestamp_ms" }),
|
|
163
|
+
confirmation: text("confirmation"),
|
|
164
|
+
scopes: text("scopes").notNull(),
|
|
165
|
+
},
|
|
166
|
+
(table) => [
|
|
167
|
+
index("oauthRefreshToken_clientId_idx").on(table.clientId),
|
|
168
|
+
index("oauthRefreshToken_sessionId_idx").on(table.sessionId),
|
|
169
|
+
index("oauthRefreshToken_userId_idx").on(table.userId),
|
|
170
|
+
index("oauthRefreshToken_authorizationCodeId_idx").on(
|
|
171
|
+
table.authorizationCodeId,
|
|
172
|
+
),
|
|
173
|
+
],
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
export const oauthAccessToken = sqliteTable(
|
|
177
|
+
"oauth_access_token",
|
|
178
|
+
{
|
|
179
|
+
id: text("id").primaryKey(),
|
|
180
|
+
token: text("token").unique(),
|
|
181
|
+
clientId: text("client_id")
|
|
182
|
+
.notNull()
|
|
183
|
+
.references(() => oauthClient.clientId),
|
|
184
|
+
sessionId: text("session_id").references(() => session.id, {
|
|
185
|
+
onDelete: "set null",
|
|
186
|
+
}),
|
|
187
|
+
userId: text("user_id").references(() => user.id),
|
|
188
|
+
referenceId: text("reference_id"),
|
|
189
|
+
authorizationCodeId: text("authorization_code_id"),
|
|
190
|
+
resources: text("resources"),
|
|
191
|
+
requestedUserInfoClaims: text("requested_user_info_claims"),
|
|
192
|
+
refreshId: text("refresh_id").references(() => oauthRefreshToken.id),
|
|
193
|
+
expiresAt: integer("expires_at", { mode: "timestamp_ms" }),
|
|
194
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" }),
|
|
195
|
+
revoked: integer("revoked", { mode: "timestamp_ms" }),
|
|
196
|
+
confirmation: text("confirmation"),
|
|
197
|
+
scopes: text("scopes").notNull(),
|
|
198
|
+
},
|
|
199
|
+
(table) => [
|
|
200
|
+
index("oauthAccessToken_clientId_idx").on(table.clientId),
|
|
201
|
+
index("oauthAccessToken_sessionId_idx").on(table.sessionId),
|
|
202
|
+
index("oauthAccessToken_userId_idx").on(table.userId),
|
|
203
|
+
index("oauthAccessToken_authorizationCodeId_idx").on(
|
|
204
|
+
table.authorizationCodeId,
|
|
205
|
+
),
|
|
206
|
+
index("oauthAccessToken_refreshId_idx").on(table.refreshId),
|
|
207
|
+
],
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
export const oauthConsent = sqliteTable(
|
|
211
|
+
"oauth_consent",
|
|
212
|
+
{
|
|
213
|
+
id: text("id").primaryKey(),
|
|
214
|
+
clientId: text("client_id")
|
|
215
|
+
.notNull()
|
|
216
|
+
.references(() => oauthClient.clientId),
|
|
217
|
+
userId: text("user_id").references(() => user.id),
|
|
218
|
+
referenceId: text("reference_id"),
|
|
219
|
+
resources: text("resources"),
|
|
220
|
+
requestedUserInfoClaims: text("requested_user_info_claims"),
|
|
221
|
+
scopes: text("scopes").notNull(),
|
|
222
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" }),
|
|
223
|
+
updatedAt: integer("updated_at", { mode: "timestamp_ms" }),
|
|
224
|
+
},
|
|
225
|
+
(table) => [
|
|
226
|
+
index("oauthConsent_clientId_idx").on(table.clientId),
|
|
227
|
+
index("oauthConsent_userId_idx").on(table.userId),
|
|
228
|
+
uniqueIndex("oauthConsent_clientId_userId_referenceId_uidx").on(
|
|
229
|
+
table.clientId,
|
|
230
|
+
table.userId,
|
|
231
|
+
table.referenceId,
|
|
232
|
+
),
|
|
233
|
+
],
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
export const oauthClientAssertion = sqliteTable("oauth_client_assertion", {
|
|
237
|
+
id: text("id").primaryKey(),
|
|
238
|
+
expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
export const oauthClientRelations = relations(oauthClient, ({ one, many }) => ({
|
|
242
|
+
user: one(user, {
|
|
243
|
+
fields: [oauthClient.userId],
|
|
244
|
+
references: [user.id],
|
|
245
|
+
}),
|
|
246
|
+
oauthClientResources: many(oauthClientResource),
|
|
247
|
+
oauthRefreshTokens: many(oauthRefreshToken),
|
|
248
|
+
oauthAccessTokens: many(oauthAccessToken),
|
|
249
|
+
oauthConsents: many(oauthConsent),
|
|
250
|
+
}));
|
|
251
|
+
|
|
252
|
+
export const oauthResourceRelations = relations(oauthResource, ({ many }) => ({
|
|
253
|
+
oauthClientResources: many(oauthClientResource),
|
|
254
|
+
}));
|
|
255
|
+
|
|
256
|
+
export const oauthClientResourceRelations = relations(
|
|
257
|
+
oauthClientResource,
|
|
258
|
+
({ one }) => ({
|
|
259
|
+
oauthClient: one(oauthClient, {
|
|
260
|
+
fields: [oauthClientResource.clientId],
|
|
261
|
+
references: [oauthClient.clientId],
|
|
262
|
+
}),
|
|
263
|
+
oauthResource: one(oauthResource, {
|
|
264
|
+
fields: [oauthClientResource.resourceId],
|
|
265
|
+
references: [oauthResource.identifier],
|
|
266
|
+
}),
|
|
267
|
+
}),
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
export const oauthRefreshTokenRelations = relations(
|
|
271
|
+
oauthRefreshToken,
|
|
272
|
+
({ one, many }) => ({
|
|
273
|
+
oauthClient: one(oauthClient, {
|
|
274
|
+
fields: [oauthRefreshToken.clientId],
|
|
275
|
+
references: [oauthClient.clientId],
|
|
276
|
+
}),
|
|
277
|
+
session: one(session, {
|
|
278
|
+
fields: [oauthRefreshToken.sessionId],
|
|
279
|
+
references: [session.id],
|
|
280
|
+
}),
|
|
281
|
+
user: one(user, {
|
|
282
|
+
fields: [oauthRefreshToken.userId],
|
|
283
|
+
references: [user.id],
|
|
284
|
+
}),
|
|
285
|
+
oauthAccessTokens: many(oauthAccessToken),
|
|
286
|
+
}),
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
export const oauthAccessTokenRelations = relations(
|
|
290
|
+
oauthAccessToken,
|
|
291
|
+
({ one }) => ({
|
|
292
|
+
oauthClient: one(oauthClient, {
|
|
293
|
+
fields: [oauthAccessToken.clientId],
|
|
294
|
+
references: [oauthClient.clientId],
|
|
295
|
+
}),
|
|
296
|
+
session: one(session, {
|
|
297
|
+
fields: [oauthAccessToken.sessionId],
|
|
298
|
+
references: [session.id],
|
|
299
|
+
}),
|
|
300
|
+
user: one(user, {
|
|
301
|
+
fields: [oauthAccessToken.userId],
|
|
302
|
+
references: [user.id],
|
|
303
|
+
}),
|
|
304
|
+
oauthRefreshToken: one(oauthRefreshToken, {
|
|
305
|
+
fields: [oauthAccessToken.refreshId],
|
|
306
|
+
references: [oauthRefreshToken.id],
|
|
307
|
+
}),
|
|
308
|
+
}),
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
export const oauthConsentRelations = relations(oauthConsent, ({ one }) => ({
|
|
312
|
+
oauthClient: one(oauthClient, {
|
|
313
|
+
fields: [oauthConsent.clientId],
|
|
314
|
+
references: [oauthClient.clientId],
|
|
315
|
+
}),
|
|
316
|
+
user: one(user, {
|
|
317
|
+
fields: [oauthConsent.userId],
|
|
318
|
+
references: [user.id],
|
|
319
|
+
}),
|
|
320
|
+
}));
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Better Auth's organization-plugin tables (`organization` / `member` / `invitation`), as Drizzle SQLite tables.
|
|
2
|
+
// Schema tables: docs/architecture/plugins/auth.md, "Schema tables".
|
|
3
|
+
|
|
4
|
+
// Drizzle types the emitted declarations spell, named through `@slotform/db`: docs/architecture/plugins/auth.md, "Schema tables".
|
|
5
|
+
// biome-ignore lint/correctness/noUnusedImports: read by the declaration emit
|
|
6
|
+
import type {
|
|
7
|
+
Many,
|
|
8
|
+
One,
|
|
9
|
+
Relations,
|
|
10
|
+
SQLiteTableWithColumns,
|
|
11
|
+
} from "@slotform/db/orm";
|
|
12
|
+
import {
|
|
13
|
+
index,
|
|
14
|
+
integer,
|
|
15
|
+
relations,
|
|
16
|
+
sql,
|
|
17
|
+
sqliteTable,
|
|
18
|
+
text,
|
|
19
|
+
} from "@slotform/db/orm";
|
|
20
|
+
import { user } from "./index.ts";
|
|
21
|
+
|
|
22
|
+
export const organization = sqliteTable("organization", {
|
|
23
|
+
id: text("id").primaryKey(),
|
|
24
|
+
name: text("name").notNull(),
|
|
25
|
+
slug: text("slug").notNull().unique(),
|
|
26
|
+
logo: text("logo"),
|
|
27
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
|
28
|
+
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
|
29
|
+
.notNull(),
|
|
30
|
+
// JSON-encoded consumer metadata; better-auth reads/writes it as a string.
|
|
31
|
+
metadata: text("metadata"),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export const member = sqliteTable(
|
|
35
|
+
"member",
|
|
36
|
+
{
|
|
37
|
+
id: text("id").primaryKey(),
|
|
38
|
+
organizationId: text("organization_id")
|
|
39
|
+
.notNull()
|
|
40
|
+
.references(() => organization.id),
|
|
41
|
+
userId: text("user_id")
|
|
42
|
+
.notNull()
|
|
43
|
+
.references(() => user.id),
|
|
44
|
+
role: text("role").notNull().default("member"),
|
|
45
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
|
46
|
+
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
|
47
|
+
.notNull(),
|
|
48
|
+
},
|
|
49
|
+
(table) => [
|
|
50
|
+
index("member_organizationId_idx").on(table.organizationId),
|
|
51
|
+
index("member_userId_idx").on(table.userId),
|
|
52
|
+
],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export const invitation = sqliteTable(
|
|
56
|
+
"invitation",
|
|
57
|
+
{
|
|
58
|
+
id: text("id").primaryKey(),
|
|
59
|
+
organizationId: text("organization_id")
|
|
60
|
+
.notNull()
|
|
61
|
+
.references(() => organization.id),
|
|
62
|
+
email: text("email").notNull(),
|
|
63
|
+
role: text("role"),
|
|
64
|
+
status: text("status").notNull().default("pending"),
|
|
65
|
+
expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
|
|
66
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
|
67
|
+
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
|
68
|
+
.notNull(),
|
|
69
|
+
inviterId: text("inviter_id")
|
|
70
|
+
.notNull()
|
|
71
|
+
.references(() => user.id),
|
|
72
|
+
},
|
|
73
|
+
(table) => [
|
|
74
|
+
index("invitation_organizationId_idx").on(table.organizationId),
|
|
75
|
+
index("invitation_email_idx").on(table.email),
|
|
76
|
+
],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
export const organizationRelations = relations(organization, ({ many }) => ({
|
|
80
|
+
members: many(member),
|
|
81
|
+
invitations: many(invitation),
|
|
82
|
+
}));
|
|
83
|
+
|
|
84
|
+
export const memberRelations = relations(member, ({ one }) => ({
|
|
85
|
+
organization: one(organization, {
|
|
86
|
+
fields: [member.organizationId],
|
|
87
|
+
references: [organization.id],
|
|
88
|
+
}),
|
|
89
|
+
user: one(user, {
|
|
90
|
+
fields: [member.userId],
|
|
91
|
+
references: [user.id],
|
|
92
|
+
}),
|
|
93
|
+
}));
|
|
94
|
+
|
|
95
|
+
export const invitationRelations = relations(invitation, ({ one }) => ({
|
|
96
|
+
organization: one(organization, {
|
|
97
|
+
fields: [invitation.organizationId],
|
|
98
|
+
references: [organization.id],
|
|
99
|
+
}),
|
|
100
|
+
inviter: one(user, {
|
|
101
|
+
fields: [invitation.inviterId],
|
|
102
|
+
references: [user.id],
|
|
103
|
+
}),
|
|
104
|
+
}));
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// The passkey plugin's table (`passkey`), as a Drizzle SQLite table.
|
|
2
|
+
// Schema tables: docs/architecture/plugins/auth.md, "Schema tables".
|
|
3
|
+
|
|
4
|
+
// Drizzle types the emitted declarations spell, named through `@slotform/db`: docs/architecture/plugins/auth.md, "Schema tables".
|
|
5
|
+
// biome-ignore lint/correctness/noUnusedImports: read by the declaration emit
|
|
6
|
+
import type { One, Relations, SQLiteTableWithColumns } from "@slotform/db/orm";
|
|
7
|
+
import { index, integer, relations, sqliteTable, text } from "@slotform/db/orm";
|
|
8
|
+
import { user } from "./index.ts";
|
|
9
|
+
|
|
10
|
+
export const passkey = sqliteTable(
|
|
11
|
+
"passkey",
|
|
12
|
+
{
|
|
13
|
+
id: text("id").primaryKey(),
|
|
14
|
+
name: text("name"),
|
|
15
|
+
publicKey: text("public_key").notNull(),
|
|
16
|
+
userId: text("user_id")
|
|
17
|
+
.notNull()
|
|
18
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
19
|
+
credentialID: text("credential_id").notNull(),
|
|
20
|
+
counter: integer("counter").notNull(),
|
|
21
|
+
deviceType: text("device_type").notNull(),
|
|
22
|
+
backedUp: integer("backed_up", { mode: "boolean" }).notNull(),
|
|
23
|
+
transports: text("transports"),
|
|
24
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" }),
|
|
25
|
+
aaguid: text("aaguid"),
|
|
26
|
+
},
|
|
27
|
+
(table) => [
|
|
28
|
+
index("passkey_userId_idx").on(table.userId),
|
|
29
|
+
index("passkey_credentialID_idx").on(table.credentialID),
|
|
30
|
+
],
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export const passkeyRelations = relations(passkey, ({ one }) => ({
|
|
34
|
+
user: one(user, {
|
|
35
|
+
fields: [passkey.userId],
|
|
36
|
+
references: [user.id],
|
|
37
|
+
}),
|
|
38
|
+
}));
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// The table set each option turns on, keyed by Better Auth model name, which is
|
|
2
|
+
// also its export name and its entity: docs/architecture/plugins/auth.md, "Schema tables".
|
|
3
|
+
import { apikey } from "./devices.ts";
|
|
4
|
+
import { account, session, user, verification } from "./index.ts";
|
|
5
|
+
import {
|
|
6
|
+
jwks,
|
|
7
|
+
oauthAccessToken,
|
|
8
|
+
oauthClient,
|
|
9
|
+
oauthClientAssertion,
|
|
10
|
+
oauthClientResource,
|
|
11
|
+
oauthConsent,
|
|
12
|
+
oauthRefreshToken,
|
|
13
|
+
oauthResource,
|
|
14
|
+
} from "./oauth.ts";
|
|
15
|
+
import { invitation, member, organization } from "./organization.ts";
|
|
16
|
+
import { passkey } from "./passkey.ts";
|
|
17
|
+
|
|
18
|
+
interface TableOptions {
|
|
19
|
+
organization?: unknown;
|
|
20
|
+
passkey?: unknown;
|
|
21
|
+
mcp?: boolean;
|
|
22
|
+
devices?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const TABLE_SETS = [
|
|
26
|
+
{
|
|
27
|
+
option: null,
|
|
28
|
+
module: "@slotform/auth/schema",
|
|
29
|
+
tables: { account, session, user, verification },
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
option: "organization",
|
|
33
|
+
module: "@slotform/auth/schema/organization",
|
|
34
|
+
tables: { invitation, member, organization },
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
option: "passkey",
|
|
38
|
+
module: "@slotform/auth/schema/passkey",
|
|
39
|
+
tables: { passkey },
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
option: "mcp",
|
|
43
|
+
module: "@slotform/auth/schema/oauth",
|
|
44
|
+
tables: {
|
|
45
|
+
jwks,
|
|
46
|
+
oauthAccessToken,
|
|
47
|
+
oauthClient,
|
|
48
|
+
oauthClientAssertion,
|
|
49
|
+
oauthClientResource,
|
|
50
|
+
oauthConsent,
|
|
51
|
+
oauthRefreshToken,
|
|
52
|
+
oauthResource,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
option: "devices",
|
|
57
|
+
module: "@slotform/auth/schema/devices",
|
|
58
|
+
tables: { apikey },
|
|
59
|
+
},
|
|
60
|
+
] as const satisfies readonly {
|
|
61
|
+
option: keyof TableOptions | null;
|
|
62
|
+
module: string;
|
|
63
|
+
tables: Record<string, unknown>;
|
|
64
|
+
}[];
|
|
65
|
+
|
|
66
|
+
export type TableSet = (typeof TABLE_SETS)[number];
|
|
67
|
+
|
|
68
|
+
// The sets the options turn on, the identity set first.
|
|
69
|
+
export function tableSetsOf(options: TableOptions): TableSet[] {
|
|
70
|
+
return TABLE_SETS.filter(
|
|
71
|
+
(set) => set.option === null || Boolean(options[set.option]),
|
|
72
|
+
);
|
|
73
|
+
}
|