import { v4 } from "uuid";

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", `${process.env.BASE_DOMAIN}oauth/github/redirect`);

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

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