aethex-forge/api/github/oauth/start.ts
Builder.io f22d76fe6d Create GitHub OAuth start endpoint
cgen-4899ef160380480abca4d7f7e7d2f1d6
2025-11-17 08:46:08 +00:00

33 lines
1 KiB
TypeScript

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);
}