Authentication updates

This commit is contained in:
Jack Mechem 2026-03-28 16:01:45 -07:00
parent 98b1daa7d3
commit 3015c98246
15 changed files with 657 additions and 165 deletions

View file

@ -1,7 +1,18 @@
import { NextResponse } from 'next/server';
import { NextRequest, NextResponse } from "next/server";
export async function GET() {
const res = await fetch('http://localhost:3001/stats');
const data = await res.json();
return NextResponse.json(data);
export async function GET(req: NextRequest) {
const token = req.cookies.get("token")?.value;
if (!token) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const res = await fetch("http://localhost:3001/stats", {
headers: { Authorization: `Bearer ${token}` },
});
if (!res.ok) {
return NextResponse.json({ error: "Unauthorized" }, { status: res.status });
}
return NextResponse.json(await res.json());
}