proper user/session creation and auth integration into UI
This commit is contained in:
@@ -1,36 +1,55 @@
|
||||
import { pgTable, text, timestamp, uuid } from 'drizzle-orm/pg-core';
|
||||
import { pgTable, text, timestamp, integer, boolean, primaryKey } from 'drizzle-orm/pg-core';
|
||||
|
||||
export const users = pgTable('users', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
email: text('email').notNull().unique(),
|
||||
export const users = pgTable('user', {
|
||||
id: text('id').primaryKey(),
|
||||
name: text('name'),
|
||||
email: text('email').notNull(),
|
||||
emailVerified: timestamp('emailVerified', { mode: 'string' }),
|
||||
image: text('image'),
|
||||
createdAt: timestamp('created_at').defaultNow().notNull(),
|
||||
updatedAt: timestamp('updated_at').defaultNow().notNull(),
|
||||
});
|
||||
|
||||
export const accounts = pgTable('accounts', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
userId: uuid('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
||||
export const accounts = pgTable('account', {
|
||||
userId: text('userId').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
||||
type: text('type').notNull(),
|
||||
provider: text('provider').notNull(),
|
||||
providerAccountId: text('provider_account_id').notNull(),
|
||||
refreshToken: text('refresh_token'),
|
||||
accessToken: text('access_token'),
|
||||
expiresAt: timestamp('expires_at'),
|
||||
tokenType: text('token_type'),
|
||||
providerAccountId: text('providerAccountId').notNull(),
|
||||
refresh_token: text('refresh_token'),
|
||||
access_token: text('access_token'),
|
||||
expires_at: text('expires_at'),
|
||||
token_type: text('token_type'),
|
||||
scope: text('scope'),
|
||||
idToken: text('id_token'),
|
||||
sessionState: text('session_state'),
|
||||
createdAt: timestamp('created_at').defaultNow().notNull(),
|
||||
updatedAt: timestamp('updated_at').defaultNow().notNull(),
|
||||
id_token: text('id_token'),
|
||||
session_state: text('session_state'),
|
||||
}, (account) => ({
|
||||
compoundKey: primaryKey({ columns: [account.provider, account.providerAccountId] })
|
||||
}));
|
||||
|
||||
export const sessions = pgTable('session', {
|
||||
sessionToken: text().primaryKey().notNull(),
|
||||
userId: text().notNull().references(() => users.id, { onDelete: 'cascade' }),
|
||||
expires: timestamp({ mode: 'string' }).notNull(),
|
||||
});
|
||||
|
||||
export const sessions = pgTable('sessions', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
sessionToken: text('session_token').notNull().unique(),
|
||||
userId: uuid('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
||||
expires: timestamp('expires').notNull(),
|
||||
createdAt: timestamp('created_at').defaultNow().notNull(),
|
||||
updatedAt: timestamp('updated_at').defaultNow().notNull(),
|
||||
});
|
||||
export const verificationTokens = pgTable('verificationToken', {
|
||||
identifier: text('identifier').notNull(),
|
||||
token: text('token').notNull(),
|
||||
expires: timestamp('expires', { mode: 'string' }).notNull(),
|
||||
}, (vt) => ({
|
||||
compoundKey: primaryKey({ columns: [vt.identifier, vt.token] })
|
||||
}));
|
||||
|
||||
export const authenticators = pgTable('authenticator', {
|
||||
credentialID: text('credentialID').notNull().unique(),
|
||||
userId: text('userId').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
||||
providerAccountId: text('providerAccountId').notNull(),
|
||||
credentialPublicKey: text('credentialPublicKey').notNull(),
|
||||
counter: integer('counter').notNull(),
|
||||
credentialDeviceType: text('credentialDeviceType').notNull(),
|
||||
credentialBackedUp: boolean('credentialBackedUp').notNull(),
|
||||
transports: text('transports'),
|
||||
}, (authenticator) => ({
|
||||
compositePK: primaryKey({
|
||||
columns: [authenticator.credentialID, authenticator.userId],
|
||||
name: "authenticator_userId_credentialID_pk"
|
||||
})
|
||||
}));
|
||||
Reference in New Issue
Block a user