import { github } from "@/server/auth/oauth";
import { generateState } from "arctic";
import { cookies } from "next/headers";

export async function GET(): Promise<Response> {
	const state = generateState();
	const url = await github.createAuthorizationURL(state);
	const ONE_HOUR = 60 * 60;

	cookies().set("github_oauth_state", state, {
		path: "/",
		secure: process.env.NODE_ENV === "production",
		httpOnly: true,
		maxAge: ONE_HOUR,
		sameSite: "lax",
	});

	return Response.redirect(url);
}
