From f22d76fe6d54ba740e45f89f4a12f325d33fe63e Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Mon, 17 Nov 2025 08:46:08 +0000 Subject: [PATCH] Create GitHub OAuth start endpoint cgen-4899ef160380480abca4d7f7e7d2f1d6 --- api/github/oauth/start.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 api/github/oauth/start.ts diff --git a/api/github/oauth/start.ts b/api/github/oauth/start.ts new file mode 100644 index 00000000..e6e7a842 --- /dev/null +++ b/api/github/oauth/start.ts @@ -0,0 +1,33 @@ +import type { VercelRequest, VercelResponse } from "@vercel/node"; + +export const config = { + runtime: "nodejs", +}; + +export default async function handler(req: VercelRequest, res: VercelResponse) { + if (req.method !== "GET") { + res.setHeader("Allow", "GET"); + return res.status(405).json({ error: "Method not allowed" }); + } + + const clientId = process.env.GITHUB_OAUTH_CLIENT_ID; + if (!clientId) { + console.error("[GitHub OAuth] Missing GITHUB_OAUTH_CLIENT_ID"); + return res.status(500).json({ error: "GitHub OAuth not configured" }); + } + + const { state } = req.query; + const apiBase = process.env.VITE_API_BASE || "https://aethex.dev"; + const redirectUri = `${apiBase}/api/github/oauth/callback`; + + // Build GitHub authorization URL + const params = new URLSearchParams({ + client_id: clientId, + redirect_uri: redirectUri, + scope: "user:email", + state: state ? decodeURIComponent(state as string) : "", + }); + + const githubAuthUrl = `https://github.com/login/oauth/authorize?${params.toString()}`; + return res.redirect(githubAuthUrl); +}