This commit is contained in:
g
2025-02-07 21:43:17 +00:00
parent 891f57d729
commit b94391c8d5
41 changed files with 66 additions and 63 deletions

View File

@@ -1,5 +1,5 @@
import dataService from '@/lib/data-service';
"use client";
import { fetchData } from "@/lib/data-service";
import { useState } from "react";
import { useRouter } from "next/navigation";
@@ -13,7 +13,6 @@ import { Label } from "@/components/ui/label";
export default function LoginPage() {
const [username, setUsername] = useState(""); // ✅ Fixed incorrect state name
const [password, setPassword] = useState("");
const [rememberMe, setRememberMe] = useState(false); // ✅ Fixed missing state
const [error, setError] = useState("");
const router = useRouter();
@@ -21,18 +20,14 @@ export default function LoginPage() {
e.preventDefault();
setError("");
const res = await dataService.fetchData("https://internal-api.inboxi.ng/api/auth/login", {
const res = await fetchData("https://internal-api.inboxi.ng/api/auth/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password }),
});
if (res.ok) {
const data = await res.json();
console.log(data);
document.cookie = `Authorization=${data.token}; path=/; Secure; SameSite=Strict; max-age=604800`;
if (res.token) {
document.cookie = `Authorization=${res.token}; path=/; Secure; SameSite=Strict; max-age=604800`;
router.push("/dashboard");
} else {
const data = await res.json();