refactor: streamline authentication flow by removing unused code, replacing custom auth utilities with NextAuth, and updating session handling in components
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 5m56s

This commit is contained in:
2025-03-28 22:24:45 +05:00
parent 99c5fef748
commit ef9f032366
10 changed files with 291 additions and 323 deletions

View File

@ -1,3 +1,4 @@
import { authOptions } from "@/app/auth";
import {
Table,
TableBody,
@ -8,9 +9,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
import { auth } from "@/app/auth";
import prisma from "@/lib/db";
import { headers } from "next/headers";
import { getServerSession } from "next-auth";
import ClickableRow from "./clickable-row";
import DeviceCard from "./device-card";
import Pagination from "./pagination";
@ -26,85 +25,84 @@ export async function DevicesTable({
}>;
parentalControl?: boolean;
}) {
const session = await auth.api.getSession({
headers: await headers(),
});
const isAdmin = session?.user.role === "ADMIN";
const session = await getServerSession(authOptions);
const isAdmin = session?.user;
const query = (await searchParams)?.query || "";
const page = (await searchParams)?.page;
const sortBy = (await searchParams)?.sortBy || "asc";
const totalDevices = await prisma.device.count({
where: {
userId: isAdmin ? undefined : session?.session.userId,
OR: [
{
name: {
contains: query || "",
mode: "insensitive",
},
},
{
mac: {
contains: query || "",
mode: "insensitive",
},
},
],
NOT: {
payments: {
some: {
paid: false,
},
},
},
isActive: isAdmin ? undefined : parentalControl,
blocked: isAdmin
? undefined
: parentalControl !== undefined
? undefined
: false,
},
});
// const totalDevices = await prisma.device.count({
// where: {
// userId: isAdmin ? undefined : session?.session.userId,
// OR: [
// {
// name: {
// contains: query || "",
// mode: "insensitive",
// },
// },
// {
// mac: {
// contains: query || "",
// mode: "insensitive",
// },
// },
// ],
// NOT: {
// payments: {
// some: {
// paid: false,
// },
// },
// },
// isActive: isAdmin ? undefined : parentalControl,
// blocked: isAdmin
// ? undefined
// : parentalControl !== undefined
// ? undefined
// : false,
// },
// });
const totalPages = Math.ceil(totalDevices / 10);
// const totalPages = Math.ceil(totalDevices / 10);
const limit = 10;
const offset = (Number(page) - 1) * limit || 0;
const devices = await prisma.device.findMany({
where: {
userId: session?.session.userId,
OR: [
{
name: {
contains: query || "",
mode: "insensitive",
},
},
{
mac: {
contains: query || "",
mode: "insensitive",
},
},
],
NOT: {
payments: {
some: {
paid: false,
},
},
},
isActive: parentalControl,
blocked: parentalControl !== undefined ? undefined : false,
},
// const devices = await prisma.device.findMany({
// where: {
// userId: session?.session.userId,
// OR: [
// {
// name: {
// contains: query || "",
// mode: "insensitive",
// },
// },
// {
// mac: {
// contains: query || "",
// mode: "insensitive",
// },
// },
// ],
// NOT: {
// payments: {
// some: {
// paid: false,
// },
// },
// },
// isActive: parentalControl,
// blocked: parentalControl !== undefined ? undefined : false,
// },
skip: offset,
take: limit,
orderBy: {
name: `${sortBy}` as "asc" | "desc",
},
});
// skip: offset,
// take: limit,
// orderBy: {
// name: `${sortBy}` as "asc" | "desc",
// },
// });
return null;
return (
<div>
{devices.length === 0 ? (