@iskra-bun/auth-kit 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/CHANGELOG.md +15 -0
- package/README.md +35 -0
- package/dist/index.d.ts +3886 -0
- package/dist/index.js +278 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
- package/src/better-auth-config.ts +186 -0
- package/src/index.ts +39 -0
- package/src/schema.ts +174 -0
- package/src/types.ts +114 -0
package/src/schema.ts
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
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";
|
|
4
|
+
|
|
5
|
+
// ==========================================
|
|
6
|
+
// PostgreSQL Schema
|
|
7
|
+
// ==========================================
|
|
8
|
+
|
|
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()
|
|
17
|
+
});
|
|
18
|
+
|
|
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)
|
|
28
|
+
});
|
|
29
|
+
|
|
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()
|
|
44
|
+
});
|
|
45
|
+
|
|
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")
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const pgSchema = {
|
|
56
|
+
user: pgUser,
|
|
57
|
+
session: pgSession,
|
|
58
|
+
account: pgAccount,
|
|
59
|
+
verification: pgVerification
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// ==========================================
|
|
63
|
+
// MySQL Schema
|
|
64
|
+
// ==========================================
|
|
65
|
+
|
|
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()
|
|
74
|
+
});
|
|
75
|
+
|
|
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)
|
|
85
|
+
});
|
|
86
|
+
|
|
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()
|
|
101
|
+
});
|
|
102
|
+
|
|
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")
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
export const mysqlSchema = {
|
|
113
|
+
user: mysqlUser,
|
|
114
|
+
session: mysqlSession,
|
|
115
|
+
account: mysqlAccount,
|
|
116
|
+
verification: mysqlVerification
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// ==========================================
|
|
120
|
+
// SQLite Schema
|
|
121
|
+
// ==========================================
|
|
122
|
+
|
|
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()
|
|
131
|
+
});
|
|
132
|
+
|
|
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)
|
|
142
|
+
});
|
|
143
|
+
|
|
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()
|
|
158
|
+
});
|
|
159
|
+
|
|
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" })
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
export const sqliteSchema = {
|
|
170
|
+
user: sqliteUser,
|
|
171
|
+
session: sqliteSession,
|
|
172
|
+
account: sqliteAccount,
|
|
173
|
+
verification: sqliteVerification
|
|
174
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth feature types and interfaces
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface User {
|
|
6
|
+
id: string;
|
|
7
|
+
email: string;
|
|
8
|
+
emailVerified: boolean;
|
|
9
|
+
name?: string | null;
|
|
10
|
+
image?: string | null;
|
|
11
|
+
createdAt: Date;
|
|
12
|
+
updatedAt: Date;
|
|
13
|
+
// deno-lint-ignore no-explicit-any
|
|
14
|
+
[key: string]: any; // Allow custom fields
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface Account {
|
|
18
|
+
id: string;
|
|
19
|
+
userId: string;
|
|
20
|
+
accountId: string;
|
|
21
|
+
providerId: string;
|
|
22
|
+
accessToken?: string;
|
|
23
|
+
refreshToken?: string;
|
|
24
|
+
idToken?: string;
|
|
25
|
+
expiresAt?: Date;
|
|
26
|
+
scope?: string;
|
|
27
|
+
password?: string; // For credentials provider
|
|
28
|
+
createdAt: Date;
|
|
29
|
+
updatedAt: Date;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface Verification {
|
|
33
|
+
id: string;
|
|
34
|
+
identifier: string; // email or phone
|
|
35
|
+
value: string; // verification token
|
|
36
|
+
expiresAt: Date;
|
|
37
|
+
createdAt: Date;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface AuthSession {
|
|
41
|
+
id: string;
|
|
42
|
+
userId: string;
|
|
43
|
+
expiresAt: Date;
|
|
44
|
+
ipAddress?: string;
|
|
45
|
+
userAgent?: string;
|
|
46
|
+
createdAt: Date;
|
|
47
|
+
updatedAt: Date;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface PasswordResetToken {
|
|
51
|
+
id: string;
|
|
52
|
+
userId: string;
|
|
53
|
+
token: string;
|
|
54
|
+
expiresAt: Date;
|
|
55
|
+
createdAt: Date;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface EmailVerificationToken {
|
|
59
|
+
id: string;
|
|
60
|
+
userId: string;
|
|
61
|
+
token: string;
|
|
62
|
+
email: string;
|
|
63
|
+
expiresAt: Date;
|
|
64
|
+
createdAt: Date;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Auth context available in route handlers
|
|
69
|
+
*/
|
|
70
|
+
export interface AuthContext {
|
|
71
|
+
user: User | null;
|
|
72
|
+
session: AuthSession | null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Registration input
|
|
77
|
+
*/
|
|
78
|
+
export interface SignUpInput {
|
|
79
|
+
email: string;
|
|
80
|
+
password: string;
|
|
81
|
+
name?: string;
|
|
82
|
+
// deno-lint-ignore no-explicit-any
|
|
83
|
+
[key: string]: any; // Allow custom fields
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Login input
|
|
88
|
+
*/
|
|
89
|
+
export interface SignInInput {
|
|
90
|
+
email: string;
|
|
91
|
+
password: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Password reset request
|
|
96
|
+
*/
|
|
97
|
+
export interface PasswordResetRequest {
|
|
98
|
+
email: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Password reset confirmation
|
|
103
|
+
*/
|
|
104
|
+
export interface PasswordResetConfirm {
|
|
105
|
+
token: string;
|
|
106
|
+
newPassword: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Email verification
|
|
111
|
+
*/
|
|
112
|
+
export interface EmailVerificationRequest {
|
|
113
|
+
token: string;
|
|
114
|
+
}
|