refactor: update authentication flow to use NextAuth, replace better-auth with axios for API calls, and clean up unused code

This commit is contained in:
2025-03-23 15:07:03 +05:00
parent 0fd269df31
commit 020d74c5e2
23 changed files with 1269 additions and 1271 deletions

View File

@ -8,7 +8,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
import { auth } from "@/lib/auth";
import { auth } from "@/app/auth";
import prisma from "@/lib/db";
import { headers } from "next/headers";
import ClickableRow from "./clickable-row";
@ -27,9 +27,9 @@ export async function DevicesTable({
parentalControl?: boolean;
}) {
const session = await auth.api.getSession({
headers: await headers()
})
const isAdmin = session?.user.role === "ADMIN"
headers: await headers(),
});
const isAdmin = session?.user.role === "ADMIN";
const query = (await searchParams)?.query || "";
const page = (await searchParams)?.page;
const sortBy = (await searchParams)?.sortBy || "asc";
@ -53,12 +53,16 @@ export async function DevicesTable({
NOT: {
payments: {
some: {
paid: false
}
}
paid: false,
},
},
},
isActive: isAdmin ? undefined : parentalControl,
blocked: isAdmin ? undefined : parentalControl !== undefined ? undefined : false,
blocked: isAdmin
? undefined
: parentalControl !== undefined
? undefined
: false,
},
});
@ -86,8 +90,8 @@ export async function DevicesTable({
NOT: {
payments: {
some: {
paid: false
}
paid: false,
},
},
},
isActive: parentalControl,
@ -158,7 +162,12 @@ export async function DevicesTable({
// )}
// </TableCell>
// </TableRow>
<ClickableRow admin={isAdmin} key={device.id} device={device} parentalControl={parentalControl} />
<ClickableRow
admin={isAdmin}
key={device.id}
device={device}
parentalControl={parentalControl}
/>
))}
</TableBody>
<TableFooter>
@ -181,7 +190,11 @@ export async function DevicesTable({
</div>
<div className="sm:hidden my-4">
{devices.map((device) => (
<DeviceCard parentalControl={parentalControl} key={device.id} device={device} />
<DeviceCard
parentalControl={parentalControl}
key={device.id}
device={device}
/>
))}
</div>
</>