lucia-auth / lucia

Authentication, simple and clean
https://lucia-auth.com
BSD Zero Clause License
9.63k stars 498 forks source link

[Feature Request]: Drizzle pg UUID support on types #1661

Closed versecafe closed 3 weeks ago

versecafe commented 3 months ago

Package

​@lucia-auth/session-drizzle

Description

Allow drizzle pg uuid types for session and user id fields instead of requiring a string

also just a note package should be @lucia-auth/adapter-drizzle

Should allow something like this

import {
  pgTable,
  timestamp,
  varchar,
  primaryKey,
  uuid,
  index,
} from "drizzle-orm/pg-core";
import { v7 as uuidv7 } from "uuid";

export const usersTable = pgTable(
  "users",
  {
    id: uuid("id").primaryKey().$defaultFn(uuidv7),
    username: varchar("username", { length: 60 }).unique().notNull(),
    avatar: varchar("avatar", { length: 2048 }),
    email: varchar("email", { length: 255 }),
    createdAt: timestamp("created_at").defaultNow().notNull(),
    lastLogin: timestamp("last_login").defaultNow().notNull(),
  },
  (table) => {
    return {
      usernameIndex: index("username_index").on(table.username),
    };
  },
);

export const sessionsTable = pgTable("sessions", {
  id: uuid("id").primaryKey().$defaultFn(uuidv7),
  userId: uuid("user_id")
    .notNull()
    .references(() => usersTable.id),
  expiresAt: timestamp("expires_at", {
    withTimezone: true,
    mode: "date",
  }).notNull(),
});
pilcrowonpaper commented 3 weeks ago

I don't plan to add any new features to the adapters. See #1714