Create Discord OAuth start endpoint
cgen-54827a549ff34e8690cccd94282ef829
This commit is contained in:
parent
ccc8108b20
commit
fd35f74b61
1 changed files with 30 additions and 0 deletions
30
api/discord/oauth/start.ts
Normal file
30
api/discord/oauth/start.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
export const config = {
|
||||||
|
runtime: "nodejs",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function handler(req: any, res: any) {
|
||||||
|
if (req.method !== "GET") {
|
||||||
|
return res.status(405).json({ error: "Method not allowed" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const clientId = process.env.DISCORD_CLIENT_ID;
|
||||||
|
if (!clientId) {
|
||||||
|
return res.status(500).json({ error: "Discord client ID not configured" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const redirectUri = `${process.env.VITE_API_BASE || "https://aethex.dev"}/api/discord/oauth/callback`;
|
||||||
|
|
||||||
|
// Get the next URL from query params (where to redirect after login)
|
||||||
|
const next = req.query.state || "/dashboard";
|
||||||
|
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
client_id: clientId,
|
||||||
|
redirect_uri: redirectUri,
|
||||||
|
response_type: "code",
|
||||||
|
scope: "identify email",
|
||||||
|
state: typeof next === "string" ? next : "/dashboard",
|
||||||
|
});
|
||||||
|
|
||||||
|
const discordOAuthUrl = `https://discord.com/api/oauth2/authorize?${params.toString()}`;
|
||||||
|
res.redirect(discordOAuthUrl);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue