mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-22 06:28:09 +02:00
feat: implement user authentication and authorization with NextAuth, including user schema, password hashing, and role-based access control.
This commit is contained in:
1 parent
c842c2447a
commit
359d196c4d
18 files changed
+652
-32
No files matched your search
@@ -2,14 +2,20 @@
|
||||
|
||||
import { db } from "@/db";
|
||||
import { sessionSnapshots } from "@/db/schema";
|
||||
import { desc, eq } from "drizzle-orm";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { and, desc, eq } from "drizzle-orm";
|
||||
|
||||
export async function getSnapshots(type?: "snapshot" | "export") {
|
||||
let query = db.select().from(sessionSnapshots);
|
||||
const session = await auth();
|
||||
const userId = session?.user ? Number((session.user as any).id) : null;
|
||||
|
||||
if (type) {
|
||||
// @ts-ignore - type column added dynamically
|
||||
return query.where(eq(sessionSnapshots.type, type)).orderBy(desc(sessionSnapshots.createdAt));
|
||||
let query = db.select().from(sessionSnapshots);
|
||||
const conditions = [];
|
||||
if (userId) conditions.push(eq(sessionSnapshots.userId, userId));
|
||||
if (type) conditions.push(eq(sessionSnapshots.type, type));
|
||||
|
||||
if (conditions.length > 0) {
|
||||
return query.where(and(...conditions)).orderBy(desc(sessionSnapshots.createdAt));
|
||||
}
|
||||
|
||||
return query.orderBy(desc(sessionSnapshots.createdAt));
|
||||
|
||||
Reference in new issue
Block a user