import { DiscordAuthProvider } from "@/auth/discord";
import { v4 } from "uuid";

export const dynamic = "force-dynamic";

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

  let params = new URLSearchParams();
  params.set("response_type", "code");
  params.set("client_id", process.env.DISCORD_CLIENT_ID);
  params.set("scope", "guilds identify email");
  params.set("state", state);
  params.set("redirect_uri", DiscordAuthProvider.redirectUri);
  params.set("prompt", "consent");

  url += "?" + params.toString();

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