verify email workflow working

This commit is contained in:
Milo Schwartz 2024-10-04 23:14:40 -04:00
parent f007e8e87f
commit a8f2ccb94b
23 changed files with 16363 additions and 15802 deletions

View file

@ -78,6 +78,9 @@ export const users = sqliteTable("user", {
.notNull()
.default(false),
twoFactorSecret: text("twoFactorSecret"),
emailVerified: integer("emailVerified", { mode: "boolean" })
.notNull()
.default(false),
});
// Sessions table
@ -85,7 +88,7 @@ export const sessions = sqliteTable("session", {
id: text("id").primaryKey(), // has to be id not sessionId for lucia
userId: text("userId")
.notNull()
.references(() => users.id),
.references(() => users.id, { onDelete: "cascade" }),
expiresAt: integer("expiresAt").notNull(),
});
@ -99,6 +102,16 @@ export const userOrgs = sqliteTable("userOrgs", {
role: text("role").notNull(), // e.g., 'admin', 'member', etc.
});
export const emailVerificationCodes = sqliteTable("emailVerificationCodes", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("userId")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
email: text("email").notNull(),
code: text("code").notNull(),
expiresAt: integer("expiresAt").notNull(),
});
// Define the model types for type inference
export type Org = InferSelectModel<typeof orgs>;
export type User = InferSelectModel<typeof users>;
@ -108,3 +121,6 @@ export type ExitNode = InferSelectModel<typeof exitNodes>;
export type Route = InferSelectModel<typeof routes>;
export type Target = InferSelectModel<typeof targets>;
export type Session = InferSelectModel<typeof sessions>;
export type EmailVerificationCode = InferSelectModel<
typeof emailVerificationCodes
>;