-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
75 lines (67 loc) · 2.38 KB
/
auth.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { relations, sql } from "drizzle-orm";
import { index, int, primaryKey, text } from "drizzle-orm/sqlite-core";
import { sqliteTable } from "./_table";
export const users = sqliteTable("user", {
id: text("id", { length: 255 }).notNull().primaryKey(),
name: text("name", { length: 255 }),
email: text("email", { length: 255 }).notNull(),
emailVerified: int("emailVerified", {
mode: "timestamp",
}).default(sql`CURRENT_TIMESTAMP(3)`),
image: text("image", { length: 255 }),
});
export const usersRelations = relations(users, ({ many }) => ({
accounts: many(accounts),
}));
export const accounts = sqliteTable(
"account",
{
userId: text("userId", { length: 255 }).notNull(),
type: text("type", { length: 255 })
.$type<"oauth" | "oidc" | "email">()
.notNull(),
provider: text("provider", { length: 255 }).notNull(),
providerAccountId: text("providerAccountId", { length: 255 }).notNull(),
refresh_token: text("refresh_token", { length: 255 }),
access_token: text("access_token"),
expires_at: int("expires_at"),
token_type: text("token_type", { length: 255 }),
scope: text("scope", { length: 255 }),
id_token: text("id_token"),
session_state: text("session_state", { length: 255 }),
},
(account) => ({
compoundKey: primaryKey({
columns: [account.provider, account.providerAccountId],
}),
userIdIdx: index("userId_idx").on(account.userId),
}),
);
export const accountsRelations = relations(accounts, ({ one }) => ({
user: one(users, { fields: [accounts.userId], references: [users.id] }),
}));
export const sessions = sqliteTable(
"session",
{
sessionToken: text("sessionToken", { length: 255 }).notNull().primaryKey(),
userId: text("userId", { length: 255 }).notNull(),
expires: int("expires", { mode: "timestamp" }).notNull(),
},
(session) => ({
userIdIdx: index("userId_idx").on(session.userId),
}),
);
export const sessionsRelations = relations(sessions, ({ one }) => ({
user: one(users, { fields: [sessions.userId], references: [users.id] }),
}));
export const verificationTokens = sqliteTable(
"verificationToken",
{
identifier: text("identifier", { length: 255 }).notNull(),
token: text("token", { length: 255 }).notNull(),
expires: int("expires", { mode: "timestamp" }).notNull(),
},
(vt) => ({
compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
}),
);