init: Initial commit

This commit is contained in:
Björn Benouarets
2026-01-19 08:42:07 +01:00
parent 1a47930d75
commit 74232ad2d2
74 changed files with 9822 additions and 98 deletions

View File

@@ -0,0 +1,31 @@
"use server";
import { cookies } from "next/headers";
export const login = async (username: string, password: string): Promise<{ success: boolean, message: string, token?: string }> => {
if (!process.env.SECNEX_API_HOST || !process.env.SECNEX_API_KEY) {
return { success: false, message: "SecNex API host or key is not set" };
}
const cookieStore = await cookies();
try {
const response = await fetch(`${process.env.SECNEX_API_HOST}/login`, {
method: "POST",
body: JSON.stringify({ username, password }),
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${process.env.SECNEX_API_KEY}`,
},
});
const dataResponse = await response.json();
const body = dataResponse.body;
cookieStore.set("token", body.token);
if (!response.ok) {
return { success: false, message: "Invalid username or password" };
}
return { success: true, message: body.message, token: body.token };
} catch (error) {
console.error(error);
return { success: false, message: "Failed to login" };
}
};