Skip to content

Commit 2c87f59

Browse files
committed
logout api and logout in header fixed
1 parent c72edd0 commit 2c87f59

File tree

3 files changed

+4
-19
lines changed

3 files changed

+4
-19
lines changed

frontend/issue-tracker-ui/src/app/admin/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ interface AdminDashboardProps {
4747
export function AdminDashboard({ user }: AdminDashboardProps) {
4848
// Mock data for demo
4949
const [users, setUsers] = useState<User[]>();
50-
5150
const [successMessage, setSuccessMessage] = useState("");
5251

5352
async function loadUsers() {

frontend/issue-tracker-ui/src/components/header.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Avatar, AvatarFallback } from "@/components/ui/avatar";
1111
import { LogOut, Triangle } from "lucide-react";
1212
import { useRouter } from "next/navigation";
1313
import { User } from "@/types/user";
14+
import { logoutUser } from "@/lib/api/auth";
1415

1516
interface HeaderProps {
1617
user: User;
@@ -20,23 +21,8 @@ export function Header({ user }: HeaderProps) {
2021
const router = useRouter();
2122
async function handleLogout() {
2223
try {
23-
const res = await fetch(
24-
"http://localhost:8080/IssuesandDeploymentTracker/api/auth/logout",
25-
{
26-
method: "POST",
27-
credentials: "include", // send cookies
28-
}
29-
);
30-
31-
if (res.ok) {
32-
// Optional: clear any client state
33-
localStorage.clear();
34-
sessionStorage.clear();
35-
36-
router.push("/auth");
37-
} else {
38-
console.error("Logout failed");
39-
}
24+
await logoutUser();
25+
router.push("/auth");
4026
} catch (err) {
4127
console.error("Logout error", err);
4228
}

frontend/issue-tracker-ui/src/lib/api/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function LoginUser(email: string, password: string) {
3030
});
3131
const data = await res.json();
3232
if (!res.ok) {
33-
alert(data.message || "Login failed.");
33+
throw new Error(data.message || "Login failed.");
3434
}
3535
return data;
3636
}

0 commit comments

Comments
 (0)