mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-02 03:38:22 +00:00
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
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 6m36s
This commit is contained in:
@ -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,
|
||||
|
Reference in New Issue
Block a user