import { NextRequest } from "next/server";
import { verifyToken } from "./auth";

export async function authenticate(request: NextRequest) {
  const authHeader = request.headers.get("authorization");

  if (!authHeader) {
    throw new Error("Authorization header missing");
  }

  const token = authHeader.replace("Bearer ", "");

  if (!token) {
    throw new Error("Token missing");
  }

  return verifyToken(token);
}