refactor: implement session checking utility, enhance device queries with session validation, and improve UI interactions for device management
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 6m36s

This commit is contained in:
2025-04-06 22:43:12 +05:00
parent 9e2a2f430e
commit daab793592
7 changed files with 256 additions and 192 deletions

View File

@ -2,6 +2,7 @@
import { authOptions } from "@/app/auth";
import type { Api400Error, ApiResponse, Device } from "@/lib/backend-types";
import { checkSession } from "@/utils/session";
import { getServerSession } from "next-auth";
import { revalidatePath } from "next/cache";
@ -12,7 +13,7 @@ type GetDevicesProps = {
status?: string;
};
export async function getDevices({ query }: GetDevicesProps) {
const session = await getServerSession(authOptions);
const session = await checkSession();
const respose = await fetch(
`${process.env.SARLINK_API_BASE_URL}/api/devices/?name=${query}`,
{
@ -27,6 +28,22 @@ export async function getDevices({ query }: GetDevicesProps) {
return data;
}
export async function getDevice({ deviceId }: { deviceId: string }) {
const session = await checkSession();
const respose = await fetch(
`${process.env.SARLINK_API_BASE_URL}/api/devices/${deviceId}/`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Token ${session?.apiToken}`,
},
},
);
const device = (await respose.json()) as Device;
return device;
}
export async function addDevice({
name,
mac,