@iskra-bun/auth-kit 0.1.0 → 0.2.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/src/schema.ts CHANGED
@@ -1,174 +1,194 @@
1
- import { pgTable, text, timestamp, boolean } from "drizzle-orm/pg-core";
2
- import { mysqlTable, varchar, timestamp as mysqlTimestamp, boolean as mysqlBoolean, text as mysqlText } from "drizzle-orm/mysql-core";
3
- import { sqliteTable, text as sqliteText, integer } from "drizzle-orm/sqlite-core";
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("user", {
10
- id: text("id").primaryKey(),
11
- name: text("name"),
12
- email: text("email").notNull().unique(),
13
- emailVerified: boolean("emailVerified").notNull(),
14
- image: text("image"),
15
- createdAt: timestamp("createdAt").notNull(),
16
- updatedAt: timestamp("updatedAt").notNull()
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("session", {
20
- id: text("id").primaryKey(),
21
- expiresAt: timestamp("expiresAt").notNull(),
22
- token: text("token").notNull().unique(),
23
- createdAt: timestamp("createdAt").notNull(),
24
- updatedAt: timestamp("updatedAt").notNull(),
25
- ipAddress: text("ipAddress"),
26
- userAgent: text("userAgent"),
27
- userId: text("userId").notNull().references(() => pgUser.id)
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("account", {
31
- id: text("id").primaryKey(),
32
- accountId: text("accountId").notNull(),
33
- providerId: text("providerId").notNull(),
34
- userId: text("userId").notNull().references(() => pgUser.id),
35
- accessToken: text("accessToken"),
36
- refreshToken: text("refreshToken"),
37
- idToken: text("idToken"),
38
- accessTokenExpiresAt: timestamp("accessTokenExpiresAt"),
39
- refreshTokenExpiresAt: timestamp("refreshTokenExpiresAt"),
40
- scope: text("scope"),
41
- password: text("password"),
42
- createdAt: timestamp("createdAt").notNull(),
43
- updatedAt: timestamp("updatedAt").notNull()
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("verification", {
47
- id: text("id").primaryKey(),
48
- identifier: text("identifier").notNull(),
49
- value: text("value").notNull(),
50
- expiresAt: timestamp("expiresAt").notNull(),
51
- createdAt: timestamp("createdAt"),
52
- updatedAt: timestamp("updatedAt")
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("user", {
67
- id: varchar("id", { length: 36 }).primaryKey(),
68
- name: varchar("name", { length: 255 }),
69
- email: varchar("email", { length: 255 }).notNull().unique(),
70
- emailVerified: mysqlBoolean("emailVerified").notNull(),
71
- image: varchar("image", { length: 255 }),
72
- createdAt: mysqlTimestamp("createdAt").notNull(),
73
- updatedAt: mysqlTimestamp("updatedAt").notNull()
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("session", {
77
- id: varchar("id", { length: 36 }).primaryKey(),
78
- expiresAt: mysqlTimestamp("expiresAt").notNull(),
79
- token: varchar("token", { length: 255 }).notNull().unique(),
80
- createdAt: mysqlTimestamp("createdAt").notNull(),
81
- updatedAt: mysqlTimestamp("updatedAt").notNull(),
82
- ipAddress: varchar("ipAddress", { length: 45 }),
83
- userAgent: mysqlText("userAgent"),
84
- userId: varchar("userId", { length: 36 }).notNull().references(() => mysqlUser.id)
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("account", {
88
- id: varchar("id", { length: 36 }).primaryKey(),
89
- accountId: varchar("accountId", { length: 255 }).notNull(),
90
- providerId: varchar("providerId", { length: 255 }).notNull(),
91
- userId: varchar("userId", { length: 36 }).notNull().references(() => mysqlUser.id),
92
- accessToken: mysqlText("accessToken"),
93
- refreshToken: mysqlText("refreshToken"),
94
- idToken: mysqlText("idToken"),
95
- accessTokenExpiresAt: mysqlTimestamp("accessTokenExpiresAt"),
96
- refreshTokenExpiresAt: mysqlTimestamp("refreshTokenExpiresAt"),
97
- scope: mysqlText("scope"),
98
- password: varchar("password", { length: 255 }),
99
- createdAt: mysqlTimestamp("createdAt").notNull(),
100
- updatedAt: mysqlTimestamp("updatedAt").notNull()
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("verification", {
104
- id: varchar("id", { length: 36 }).primaryKey(),
105
- identifier: varchar("identifier", { length: 255 }).notNull(),
106
- value: varchar("value", { length: 255 }).notNull(),
107
- expiresAt: mysqlTimestamp("expiresAt").notNull(),
108
- createdAt: mysqlTimestamp("createdAt"),
109
- updatedAt: mysqlTimestamp("updatedAt")
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("user", {
124
- id: sqliteText("id").primaryKey(),
125
- name: sqliteText("name"),
126
- email: sqliteText("email").notNull().unique(),
127
- emailVerified: integer("emailVerified", { mode: "boolean" }).notNull(),
128
- image: sqliteText("image"),
129
- createdAt: integer("createdAt", { mode: "timestamp" }).notNull(),
130
- updatedAt: integer("updatedAt", { mode: "timestamp" }).notNull()
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("session", {
134
- id: sqliteText("id").primaryKey(),
135
- expiresAt: integer("expiresAt", { mode: "timestamp" }).notNull(),
136
- token: sqliteText("token").notNull().unique(),
137
- createdAt: integer("createdAt", { mode: "timestamp" }).notNull(),
138
- updatedAt: integer("updatedAt", { mode: "timestamp" }).notNull(),
139
- ipAddress: sqliteText("ipAddress"),
140
- userAgent: sqliteText("userAgent"),
141
- userId: sqliteText("userId").notNull().references(() => sqliteUser.id)
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("account", {
145
- id: sqliteText("id").primaryKey(),
146
- accountId: sqliteText("accountId").notNull(),
147
- providerId: sqliteText("providerId").notNull(),
148
- userId: sqliteText("userId").notNull().references(() => sqliteUser.id),
149
- accessToken: sqliteText("accessToken"),
150
- refreshToken: sqliteText("refreshToken"),
151
- idToken: sqliteText("idToken"),
152
- accessTokenExpiresAt: integer("accessTokenExpiresAt", { mode: "timestamp" }),
153
- refreshTokenExpiresAt: integer("refreshTokenExpiresAt", { mode: "timestamp" }),
154
- scope: sqliteText("scope"),
155
- password: sqliteText("password"),
156
- createdAt: integer("createdAt", { mode: "timestamp" }).notNull(),
157
- updatedAt: integer("updatedAt", { mode: "timestamp" }).notNull()
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("verification", {
161
- id: sqliteText("id").primaryKey(),
162
- identifier: sqliteText("identifier").notNull(),
163
- value: sqliteText("value").notNull(),
164
- expiresAt: integer("expiresAt", { mode: "timestamp" }).notNull(),
165
- createdAt: integer("createdAt", { mode: "timestamp" }),
166
- updatedAt: integer("updatedAt", { mode: "timestamp" })
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
- // deno-lint-ignore no-explicit-any
14
- [key: string]: any; // Allow custom fields
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
- // deno-lint-ignore no-explicit-any
83
- [key: string]: any; // Allow custom fields
82
+ /** Custom fields: narrow them where they are read. */
83
+ [key: string]: unknown;
84
84
  }
85
85
 
86
86
  /**