import { GitHubAuthProvider } from "@/auth/github";
import { v4 } from "uuid";

export const dynamic = "force-dynamic";

export async function GET(request: Request) {
  let url = `https://github.com/login/oauth/authorize`;
  let state = v4();

  let params = new URLSearchParams();
  params.set("client_id", process.env.GITHUB_CLIENT_ID);
  params.set("scope", "user");
  params.set("state", state);
  params.set("redirect_uri", GitHubAuthProvider.redirectUri);

  url += `?${params.toString()}`;

  return new Response(null, {
    status: 302,
    headers: {
      Location: url,
      "Set-Cookie": `state=${state}; Path=/;`
    }
  });
}
