scaffold auth
parent
f7355f8576
commit
1acd519951
@ -0,0 +1,27 @@
|
|||||||
|
import { lucia } from "lucia";
|
||||||
|
import { web } from "lucia/middleware";
|
||||||
|
import { libsql } from "@lucia-auth/adapter-sqlite";
|
||||||
|
import { config } from "../config";
|
||||||
|
import { client } from "../db";
|
||||||
|
|
||||||
|
const envAliasMap = {
|
||||||
|
production: "PROD",
|
||||||
|
development: "DEV",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
const envAlias = envAliasMap[config.env.NODE_ENV];
|
||||||
|
|
||||||
|
export const auth = lucia({
|
||||||
|
env: envAlias,
|
||||||
|
middleware: web(),
|
||||||
|
sessionCookie: {
|
||||||
|
expires: false,
|
||||||
|
},
|
||||||
|
adapter: libsql(client, {
|
||||||
|
user: "user",
|
||||||
|
key: "user_key",
|
||||||
|
session: "user_session",
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type Auth = typeof auth;
|
@ -0,0 +1,27 @@
|
|||||||
|
import { sqliteTable, text, blob } from "drizzle-orm/sqlite-core";
|
||||||
|
|
||||||
|
export const user = sqliteTable("user", {
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
// other user attributes
|
||||||
|
});
|
||||||
|
|
||||||
|
export const session = sqliteTable("user_session", {
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
userId: text("user_id")
|
||||||
|
.notNull()
|
||||||
|
.references(() => user.id),
|
||||||
|
activeExpires: blob("active_expires", {
|
||||||
|
mode: "bigint",
|
||||||
|
}).notNull(),
|
||||||
|
idleExpires: blob("idle_expires", {
|
||||||
|
mode: "bigint",
|
||||||
|
}).notNull(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const key = sqliteTable("user_key", {
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
userId: text("user_id")
|
||||||
|
.notNull()
|
||||||
|
.references(() => user.id),
|
||||||
|
hashedPassword: text("hashed_password"),
|
||||||
|
});
|
@ -1 +1,2 @@
|
|||||||
export { todos } from "./todos";
|
export { todos } from "./todos";
|
||||||
|
export * from "./auth"
|
@ -0,0 +1,6 @@
|
|||||||
|
/// <reference types="lucia" />
|
||||||
|
declare namespace Lucia {
|
||||||
|
type Auth = import("../auth/index").Auth;
|
||||||
|
type DatabaseUserAttributes = {};
|
||||||
|
type DatabaseSessionAttributes = {};
|
||||||
|
}
|
Loading…
Reference in New Issue