[Closes #8] Added authentication
Some checks failed
Production Build and Deploy / Build (push) Failing after 44s
Production Build and Deploy / Deploy (push) Has been skipped

This commit is contained in:
Liviu Burcusel 2026-01-07 11:11:35 +01:00
parent 6eefa137bb
commit 97211cdccd
Signed by: liviu
GPG key ID: 6CDB37A4AD2C610C
65 changed files with 5831 additions and 440 deletions

View file

@ -0,0 +1,106 @@
import { v7 as uuidv7 } from "uuid";
import { relations, sql } from "drizzle-orm";
import { boolean, index, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
export const user = pgTable("user", {
id: uuid()
.primaryKey()
.default(sql`uuid_v7()`)
.$defaultFn(() => uuidv7()),
name: text().notNull(),
email: text().notNull().unique(),
emailVerified: boolean().default(false).notNull(),
image: text(),
createdAt: timestamp().defaultNow().notNull(),
updatedAt: timestamp()
.defaultNow()
.$onUpdate(() => new Date())
.notNull(),
});
export const session = pgTable(
"session",
{
id: uuid()
.primaryKey()
.default(sql`uuid_v7()`)
.$defaultFn(() => uuidv7()),
expiresAt: timestamp().notNull(),
token: text().notNull().unique(),
createdAt: timestamp().defaultNow().notNull(),
updatedAt: timestamp()
.$onUpdate(() => new Date())
.notNull(),
ipAddress: text(),
userAgent: text(),
userId: uuid()
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
},
(table) => [index("session_userId_idx").on(table.userId)]
);
export const account = pgTable(
"account",
{
id: uuid()
.primaryKey()
.default(sql`uuid_v7()`)
.$defaultFn(() => uuidv7()),
accountId: text().notNull(),
providerId: text().notNull(),
userId: uuid()
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
accessToken: text(),
refreshToken: text(),
idToken: text(),
accessTokenExpiresAt: timestamp(),
refreshTokenExpiresAt: timestamp(),
scope: text(),
password: text(),
createdAt: timestamp().defaultNow().notNull(),
updatedAt: timestamp()
.$onUpdate(() => new Date())
.notNull(),
},
(table) => [index("account_userId_idx").on(table.userId)]
);
export const verification = pgTable(
"verification",
{
id: uuid()
.primaryKey()
.default(sql`uuid_v7()`)
.$defaultFn(() => uuidv7()),
identifier: text().notNull(),
value: text().notNull(),
expiresAt: timestamp().notNull(),
createdAt: timestamp().defaultNow().notNull(),
updatedAt: timestamp()
.defaultNow()
.$onUpdate(() => new Date())
.notNull(),
},
(table) => [index("verification_identifier_idx").on(table.identifier)]
);
export const userRelations = relations(user, ({ many }) => ({
sessions: many(session),
accounts: many(account),
}));
export const sessionRelations = relations(session, ({ one }) => ({
user: one(user, {
fields: [session.userId],
references: [user.id],
}),
}));
export const accountRelations = relations(account, ({ one }) => ({
user: one(user, {
fields: [account.userId],
references: [user.id],
}),
}));

View file

@ -0,0 +1,2 @@
export * from "./auth";
export * from "./memberData";

View file

@ -0,0 +1,21 @@
import { relations } from "drizzle-orm";
import { jsonb, pgTable, text, uuid } from "drizzle-orm/pg-core";
import { user } from "./auth";
export const memberData = pgTable("member_data", {
id: uuid()
.primaryKey()
.references(() => user.id, { onDelete: "cascade" }),
country: text(),
info: jsonb(),
address: jsonb(),
billing: jsonb(),
});
export const memberDataRelations = relations(memberData, ({ one }) => ({
user: one(user, {
fields: [memberData.id],
references: [user.id],
}),
}));