@iskra-bun/auth-kit 0.1.0 → 0.2.1
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/CHANGELOG.md +58 -0
- package/README.md +1 -1
- package/dist/index.d.ts +103 -19
- package/dist/index.js +103 -37
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
- package/src/better-auth-config.ts +207 -72
- package/src/index.ts +7 -3
- package/src/schema.ts +140 -120
- package/src/types.ts +4 -4
package/src/schema.ts
CHANGED
|
@@ -1,174 +1,194 @@
|
|
|
1
|
-
import { pgTable, text, timestamp, boolean } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { pgTable, text, timestamp, boolean } from 'drizzle-orm/pg-core';
|
|
2
|
+
import {
|
|
3
|
+
mysqlTable,
|
|
4
|
+
varchar,
|
|
5
|
+
timestamp as mysqlTimestamp,
|
|
6
|
+
boolean as mysqlBoolean,
|
|
7
|
+
text as mysqlText,
|
|
8
|
+
} from 'drizzle-orm/mysql-core';
|
|
9
|
+
import { sqliteTable, text as sqliteText, integer } from 'drizzle-orm/sqlite-core';
|
|
4
10
|
|
|
5
11
|
// ==========================================
|
|
6
12
|
// PostgreSQL Schema
|
|
7
13
|
// ==========================================
|
|
8
14
|
|
|
9
|
-
export const pgUser = pgTable(
|
|
10
|
-
id: text(
|
|
11
|
-
name: text(
|
|
12
|
-
email: text(
|
|
13
|
-
emailVerified: boolean(
|
|
14
|
-
image: text(
|
|
15
|
-
createdAt: timestamp(
|
|
16
|
-
updatedAt: timestamp(
|
|
15
|
+
export const pgUser = pgTable('user', {
|
|
16
|
+
id: text('id').primaryKey(),
|
|
17
|
+
name: text('name'),
|
|
18
|
+
email: text('email').notNull().unique(),
|
|
19
|
+
emailVerified: boolean('emailVerified').notNull(),
|
|
20
|
+
image: text('image'),
|
|
21
|
+
createdAt: timestamp('createdAt').notNull(),
|
|
22
|
+
updatedAt: timestamp('updatedAt').notNull(),
|
|
17
23
|
});
|
|
18
24
|
|
|
19
|
-
export const pgSession = pgTable(
|
|
20
|
-
id: text(
|
|
21
|
-
expiresAt: timestamp(
|
|
22
|
-
token: text(
|
|
23
|
-
createdAt: timestamp(
|
|
24
|
-
updatedAt: timestamp(
|
|
25
|
-
ipAddress: text(
|
|
26
|
-
userAgent: text(
|
|
27
|
-
userId: text(
|
|
25
|
+
export const pgSession = pgTable('session', {
|
|
26
|
+
id: text('id').primaryKey(),
|
|
27
|
+
expiresAt: timestamp('expiresAt').notNull(),
|
|
28
|
+
token: text('token').notNull().unique(),
|
|
29
|
+
createdAt: timestamp('createdAt').notNull(),
|
|
30
|
+
updatedAt: timestamp('updatedAt').notNull(),
|
|
31
|
+
ipAddress: text('ipAddress'),
|
|
32
|
+
userAgent: text('userAgent'),
|
|
33
|
+
userId: text('userId')
|
|
34
|
+
.notNull()
|
|
35
|
+
.references(() => pgUser.id),
|
|
28
36
|
});
|
|
29
37
|
|
|
30
|
-
export const pgAccount = pgTable(
|
|
31
|
-
id: text(
|
|
32
|
-
accountId: text(
|
|
33
|
-
providerId: text(
|
|
34
|
-
userId: text(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
export const pgAccount = pgTable('account', {
|
|
39
|
+
id: text('id').primaryKey(),
|
|
40
|
+
accountId: text('accountId').notNull(),
|
|
41
|
+
providerId: text('providerId').notNull(),
|
|
42
|
+
userId: text('userId')
|
|
43
|
+
.notNull()
|
|
44
|
+
.references(() => pgUser.id),
|
|
45
|
+
accessToken: text('accessToken'),
|
|
46
|
+
refreshToken: text('refreshToken'),
|
|
47
|
+
idToken: text('idToken'),
|
|
48
|
+
accessTokenExpiresAt: timestamp('accessTokenExpiresAt'),
|
|
49
|
+
refreshTokenExpiresAt: timestamp('refreshTokenExpiresAt'),
|
|
50
|
+
scope: text('scope'),
|
|
51
|
+
password: text('password'),
|
|
52
|
+
createdAt: timestamp('createdAt').notNull(),
|
|
53
|
+
updatedAt: timestamp('updatedAt').notNull(),
|
|
44
54
|
});
|
|
45
55
|
|
|
46
|
-
export const pgVerification = pgTable(
|
|
47
|
-
id: text(
|
|
48
|
-
identifier: text(
|
|
49
|
-
value: text(
|
|
50
|
-
expiresAt: timestamp(
|
|
51
|
-
createdAt: timestamp(
|
|
52
|
-
updatedAt: timestamp(
|
|
56
|
+
export const pgVerification = pgTable('verification', {
|
|
57
|
+
id: text('id').primaryKey(),
|
|
58
|
+
identifier: text('identifier').notNull(),
|
|
59
|
+
value: text('value').notNull(),
|
|
60
|
+
expiresAt: timestamp('expiresAt').notNull(),
|
|
61
|
+
createdAt: timestamp('createdAt'),
|
|
62
|
+
updatedAt: timestamp('updatedAt'),
|
|
53
63
|
});
|
|
54
64
|
|
|
55
65
|
export const pgSchema = {
|
|
56
66
|
user: pgUser,
|
|
57
67
|
session: pgSession,
|
|
58
68
|
account: pgAccount,
|
|
59
|
-
verification: pgVerification
|
|
69
|
+
verification: pgVerification,
|
|
60
70
|
};
|
|
61
71
|
|
|
62
72
|
// ==========================================
|
|
63
73
|
// MySQL Schema
|
|
64
74
|
// ==========================================
|
|
65
75
|
|
|
66
|
-
export const mysqlUser = mysqlTable(
|
|
67
|
-
id: varchar(
|
|
68
|
-
name: varchar(
|
|
69
|
-
email: varchar(
|
|
70
|
-
emailVerified: mysqlBoolean(
|
|
71
|
-
image: varchar(
|
|
72
|
-
createdAt: mysqlTimestamp(
|
|
73
|
-
updatedAt: mysqlTimestamp(
|
|
76
|
+
export const mysqlUser = mysqlTable('user', {
|
|
77
|
+
id: varchar('id', { length: 36 }).primaryKey(),
|
|
78
|
+
name: varchar('name', { length: 255 }),
|
|
79
|
+
email: varchar('email', { length: 255 }).notNull().unique(),
|
|
80
|
+
emailVerified: mysqlBoolean('emailVerified').notNull(),
|
|
81
|
+
image: varchar('image', { length: 255 }),
|
|
82
|
+
createdAt: mysqlTimestamp('createdAt').notNull(),
|
|
83
|
+
updatedAt: mysqlTimestamp('updatedAt').notNull(),
|
|
74
84
|
});
|
|
75
85
|
|
|
76
|
-
export const mysqlSession = mysqlTable(
|
|
77
|
-
id: varchar(
|
|
78
|
-
expiresAt: mysqlTimestamp(
|
|
79
|
-
token: varchar(
|
|
80
|
-
createdAt: mysqlTimestamp(
|
|
81
|
-
updatedAt: mysqlTimestamp(
|
|
82
|
-
ipAddress: varchar(
|
|
83
|
-
userAgent: mysqlText(
|
|
84
|
-
userId: varchar(
|
|
86
|
+
export const mysqlSession = mysqlTable('session', {
|
|
87
|
+
id: varchar('id', { length: 36 }).primaryKey(),
|
|
88
|
+
expiresAt: mysqlTimestamp('expiresAt').notNull(),
|
|
89
|
+
token: varchar('token', { length: 255 }).notNull().unique(),
|
|
90
|
+
createdAt: mysqlTimestamp('createdAt').notNull(),
|
|
91
|
+
updatedAt: mysqlTimestamp('updatedAt').notNull(),
|
|
92
|
+
ipAddress: varchar('ipAddress', { length: 45 }),
|
|
93
|
+
userAgent: mysqlText('userAgent'),
|
|
94
|
+
userId: varchar('userId', { length: 36 })
|
|
95
|
+
.notNull()
|
|
96
|
+
.references(() => mysqlUser.id),
|
|
85
97
|
});
|
|
86
98
|
|
|
87
|
-
export const mysqlAccount = mysqlTable(
|
|
88
|
-
id: varchar(
|
|
89
|
-
accountId: varchar(
|
|
90
|
-
providerId: varchar(
|
|
91
|
-
userId: varchar(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
export const mysqlAccount = mysqlTable('account', {
|
|
100
|
+
id: varchar('id', { length: 36 }).primaryKey(),
|
|
101
|
+
accountId: varchar('accountId', { length: 255 }).notNull(),
|
|
102
|
+
providerId: varchar('providerId', { length: 255 }).notNull(),
|
|
103
|
+
userId: varchar('userId', { length: 36 })
|
|
104
|
+
.notNull()
|
|
105
|
+
.references(() => mysqlUser.id),
|
|
106
|
+
accessToken: mysqlText('accessToken'),
|
|
107
|
+
refreshToken: mysqlText('refreshToken'),
|
|
108
|
+
idToken: mysqlText('idToken'),
|
|
109
|
+
accessTokenExpiresAt: mysqlTimestamp('accessTokenExpiresAt'),
|
|
110
|
+
refreshTokenExpiresAt: mysqlTimestamp('refreshTokenExpiresAt'),
|
|
111
|
+
scope: mysqlText('scope'),
|
|
112
|
+
password: varchar('password', { length: 255 }),
|
|
113
|
+
createdAt: mysqlTimestamp('createdAt').notNull(),
|
|
114
|
+
updatedAt: mysqlTimestamp('updatedAt').notNull(),
|
|
101
115
|
});
|
|
102
116
|
|
|
103
|
-
export const mysqlVerification = mysqlTable(
|
|
104
|
-
id: varchar(
|
|
105
|
-
identifier: varchar(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
117
|
+
export const mysqlVerification = mysqlTable('verification', {
|
|
118
|
+
id: varchar('id', { length: 36 }).primaryKey(),
|
|
119
|
+
identifier: varchar('identifier', { length: 255 }).notNull(),
|
|
120
|
+
// text: better-auth stores OAuth state here (JSON longer than 255 characters),
|
|
121
|
+
// which MySQL strict mode rejected, failing every OIDC sign-in.
|
|
122
|
+
value: mysqlText('value').notNull(),
|
|
123
|
+
expiresAt: mysqlTimestamp('expiresAt').notNull(),
|
|
124
|
+
createdAt: mysqlTimestamp('createdAt'),
|
|
125
|
+
updatedAt: mysqlTimestamp('updatedAt'),
|
|
110
126
|
});
|
|
111
127
|
|
|
112
128
|
export const mysqlSchema = {
|
|
113
129
|
user: mysqlUser,
|
|
114
130
|
session: mysqlSession,
|
|
115
131
|
account: mysqlAccount,
|
|
116
|
-
verification: mysqlVerification
|
|
132
|
+
verification: mysqlVerification,
|
|
117
133
|
};
|
|
118
134
|
|
|
119
135
|
// ==========================================
|
|
120
136
|
// SQLite Schema
|
|
121
137
|
// ==========================================
|
|
122
138
|
|
|
123
|
-
export const sqliteUser = sqliteTable(
|
|
124
|
-
id: sqliteText(
|
|
125
|
-
name: sqliteText(
|
|
126
|
-
email: sqliteText(
|
|
127
|
-
emailVerified: integer(
|
|
128
|
-
image: sqliteText(
|
|
129
|
-
createdAt: integer(
|
|
130
|
-
updatedAt: integer(
|
|
139
|
+
export const sqliteUser = sqliteTable('user', {
|
|
140
|
+
id: sqliteText('id').primaryKey(),
|
|
141
|
+
name: sqliteText('name'),
|
|
142
|
+
email: sqliteText('email').notNull().unique(),
|
|
143
|
+
emailVerified: integer('emailVerified', { mode: 'boolean' }).notNull(),
|
|
144
|
+
image: sqliteText('image'),
|
|
145
|
+
createdAt: integer('createdAt', { mode: 'timestamp' }).notNull(),
|
|
146
|
+
updatedAt: integer('updatedAt', { mode: 'timestamp' }).notNull(),
|
|
131
147
|
});
|
|
132
148
|
|
|
133
|
-
export const sqliteSession = sqliteTable(
|
|
134
|
-
id: sqliteText(
|
|
135
|
-
expiresAt: integer(
|
|
136
|
-
token: sqliteText(
|
|
137
|
-
createdAt: integer(
|
|
138
|
-
updatedAt: integer(
|
|
139
|
-
ipAddress: sqliteText(
|
|
140
|
-
userAgent: sqliteText(
|
|
141
|
-
userId: sqliteText(
|
|
149
|
+
export const sqliteSession = sqliteTable('session', {
|
|
150
|
+
id: sqliteText('id').primaryKey(),
|
|
151
|
+
expiresAt: integer('expiresAt', { mode: 'timestamp' }).notNull(),
|
|
152
|
+
token: sqliteText('token').notNull().unique(),
|
|
153
|
+
createdAt: integer('createdAt', { mode: 'timestamp' }).notNull(),
|
|
154
|
+
updatedAt: integer('updatedAt', { mode: 'timestamp' }).notNull(),
|
|
155
|
+
ipAddress: sqliteText('ipAddress'),
|
|
156
|
+
userAgent: sqliteText('userAgent'),
|
|
157
|
+
userId: sqliteText('userId')
|
|
158
|
+
.notNull()
|
|
159
|
+
.references(() => sqliteUser.id),
|
|
142
160
|
});
|
|
143
161
|
|
|
144
|
-
export const sqliteAccount = sqliteTable(
|
|
145
|
-
id: sqliteText(
|
|
146
|
-
accountId: sqliteText(
|
|
147
|
-
providerId: sqliteText(
|
|
148
|
-
userId: sqliteText(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
162
|
+
export const sqliteAccount = sqliteTable('account', {
|
|
163
|
+
id: sqliteText('id').primaryKey(),
|
|
164
|
+
accountId: sqliteText('accountId').notNull(),
|
|
165
|
+
providerId: sqliteText('providerId').notNull(),
|
|
166
|
+
userId: sqliteText('userId')
|
|
167
|
+
.notNull()
|
|
168
|
+
.references(() => sqliteUser.id),
|
|
169
|
+
accessToken: sqliteText('accessToken'),
|
|
170
|
+
refreshToken: sqliteText('refreshToken'),
|
|
171
|
+
idToken: sqliteText('idToken'),
|
|
172
|
+
accessTokenExpiresAt: integer('accessTokenExpiresAt', { mode: 'timestamp' }),
|
|
173
|
+
refreshTokenExpiresAt: integer('refreshTokenExpiresAt', { mode: 'timestamp' }),
|
|
174
|
+
scope: sqliteText('scope'),
|
|
175
|
+
password: sqliteText('password'),
|
|
176
|
+
createdAt: integer('createdAt', { mode: 'timestamp' }).notNull(),
|
|
177
|
+
updatedAt: integer('updatedAt', { mode: 'timestamp' }).notNull(),
|
|
158
178
|
});
|
|
159
179
|
|
|
160
|
-
export const sqliteVerification = sqliteTable(
|
|
161
|
-
id: sqliteText(
|
|
162
|
-
identifier: sqliteText(
|
|
163
|
-
value: sqliteText(
|
|
164
|
-
expiresAt: integer(
|
|
165
|
-
createdAt: integer(
|
|
166
|
-
updatedAt: integer(
|
|
180
|
+
export const sqliteVerification = sqliteTable('verification', {
|
|
181
|
+
id: sqliteText('id').primaryKey(),
|
|
182
|
+
identifier: sqliteText('identifier').notNull(),
|
|
183
|
+
value: sqliteText('value').notNull(),
|
|
184
|
+
expiresAt: integer('expiresAt', { mode: 'timestamp' }).notNull(),
|
|
185
|
+
createdAt: integer('createdAt', { mode: 'timestamp' }),
|
|
186
|
+
updatedAt: integer('updatedAt', { mode: 'timestamp' }),
|
|
167
187
|
});
|
|
168
188
|
|
|
169
189
|
export const sqliteSchema = {
|
|
170
190
|
user: sqliteUser,
|
|
171
191
|
session: sqliteSession,
|
|
172
192
|
account: sqliteAccount,
|
|
173
|
-
verification: sqliteVerification
|
|
193
|
+
verification: sqliteVerification,
|
|
174
194
|
};
|
package/src/types.ts
CHANGED
|
@@ -10,8 +10,8 @@ export interface User {
|
|
|
10
10
|
image?: string | null;
|
|
11
11
|
createdAt: Date;
|
|
12
12
|
updatedAt: Date;
|
|
13
|
-
|
|
14
|
-
[key: string]:
|
|
13
|
+
/** Custom fields: narrow them where they are read. */
|
|
14
|
+
[key: string]: unknown;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export interface Account {
|
|
@@ -79,8 +79,8 @@ export interface SignUpInput {
|
|
|
79
79
|
email: string;
|
|
80
80
|
password: string;
|
|
81
81
|
name?: string;
|
|
82
|
-
|
|
83
|
-
[key: string]:
|
|
82
|
+
/** Custom fields: narrow them where they are read. */
|
|
83
|
+
[key: string]: unknown;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/**
|