diff --git a/api/discord/oauth/callback.ts b/api/discord/oauth/callback.ts
index bf35ef16..8b869293 100644
--- a/api/discord/oauth/callback.ts
+++ b/api/discord/oauth/callback.ts
@@ -49,19 +49,22 @@ export default async function handler(req: any, res: any) {
const redirectUri = `${process.env.VITE_API_BASE || "https://aethex.dev"}/api/discord/oauth/callback`;
// Exchange code for access token
- const tokenResponse = await fetch("https://discord.com/api/v10/oauth2/token", {
- method: "POST",
- headers: {
- "Content-Type": "application/x-www-form-urlencoded",
+ const tokenResponse = await fetch(
+ "https://discord.com/api/v10/oauth2/token",
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/x-www-form-urlencoded",
+ },
+ body: new URLSearchParams({
+ client_id: clientId,
+ client_secret: clientSecret,
+ grant_type: "authorization_code",
+ code,
+ redirect_uri: redirectUri,
+ }).toString(),
},
- body: new URLSearchParams({
- client_id: clientId,
- client_secret: clientSecret,
- grant_type: "authorization_code",
- code,
- redirect_uri: redirectUri,
- }).toString(),
- });
+ );
if (!tokenResponse.ok) {
const errorData = await tokenResponse.json();
@@ -115,19 +118,23 @@ export default async function handler(req: any, res: any) {
} else {
// Create new user
// First create auth user
- const { data: authData, error: authError } = await supabase.auth.admin.createUser({
- email: discordUser.email,
- email_confirm: true,
- user_metadata: {
- full_name: discordUser.username,
- avatar_url: discordUser.avatar
- ? `https://cdn.discordapp.com/avatars/${discordUser.id}/${discordUser.avatar}.png`
- : null,
- },
- });
+ const { data: authData, error: authError } =
+ await supabase.auth.admin.createUser({
+ email: discordUser.email,
+ email_confirm: true,
+ user_metadata: {
+ full_name: discordUser.username,
+ avatar_url: discordUser.avatar
+ ? `https://cdn.discordapp.com/avatars/${discordUser.id}/${discordUser.avatar}.png`
+ : null,
+ },
+ });
if (authError || !authData.user) {
- console.error("[Discord OAuth] Auth user creation failed:", authError);
+ console.error(
+ "[Discord OAuth] Auth user creation failed:",
+ authError,
+ );
return res.redirect("/login?error=auth_create");
}
@@ -135,17 +142,22 @@ export default async function handler(req: any, res: any) {
isNewUser = true;
// Create user profile
- const { error: profileError } = await supabase.from("user_profiles").insert({
- id: userId,
- email: discordUser.email,
- full_name: discordUser.username,
- avatar_url: discordUser.avatar
- ? `https://cdn.discordapp.com/avatars/${discordUser.id}/${discordUser.avatar}.png`
- : null,
- });
+ const { error: profileError } = await supabase
+ .from("user_profiles")
+ .insert({
+ id: userId,
+ email: discordUser.email,
+ full_name: discordUser.username,
+ avatar_url: discordUser.avatar
+ ? `https://cdn.discordapp.com/avatars/${discordUser.id}/${discordUser.avatar}.png`
+ : null,
+ });
if (profileError) {
- console.error("[Discord OAuth] Profile creation failed:", profileError);
+ console.error(
+ "[Discord OAuth] Profile creation failed:",
+ profileError,
+ );
return res.redirect("/login?error=profile_create");
}
}
@@ -164,9 +176,10 @@ export default async function handler(req: any, res: any) {
}
// Generate session token
- const { data: sessionData, error: sessionError } = await supabase.auth.admin.createSession({
- user_id: userId,
- });
+ const { data: sessionData, error: sessionError } =
+ await supabase.auth.admin.createSession({
+ user_id: userId,
+ });
if (sessionError || !sessionData.session) {
console.error("[Discord OAuth] Session creation failed:", sessionError);
@@ -174,17 +187,25 @@ export default async function handler(req: any, res: any) {
}
// Redirect to next page with session
- const nextPath = state && typeof state === "string" && state.startsWith("/") ? state : isNewUser ? "/onboarding" : "/dashboard";
- const redirectUrl = new URL(nextPath, process.env.VITE_API_BASE || "https://aethex.dev");
-
+ const nextPath =
+ state && typeof state === "string" && state.startsWith("/")
+ ? state
+ : isNewUser
+ ? "/onboarding"
+ : "/dashboard";
+ const redirectUrl = new URL(
+ nextPath,
+ process.env.VITE_API_BASE || "https://aethex.dev",
+ );
+
// Set cookies for session (similar to how Supabase does it)
res.setHeader(
"Set-Cookie",
- `sb-access-token=${sessionData.session.access_token}; Path=/; HttpOnly; Secure; SameSite=Lax`
+ `sb-access-token=${sessionData.session.access_token}; Path=/; HttpOnly; Secure; SameSite=Lax`,
);
res.setHeader(
"Set-Cookie",
- `sb-refresh-token=${sessionData.session.refresh_token}; Path=/; HttpOnly; Secure; SameSite=Lax`
+ `sb-refresh-token=${sessionData.session.refresh_token}; Path=/; HttpOnly; Secure; SameSite=Lax`,
);
res.redirect(redirectUrl.toString());
diff --git a/api/discord/oauth/start.ts b/api/discord/oauth/start.ts
index 4197d703..f8083bf9 100644
--- a/api/discord/oauth/start.ts
+++ b/api/discord/oauth/start.ts
@@ -13,10 +13,10 @@ export default function handler(req: any, res: any) {
}
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,
diff --git a/api/discord/verify-code.ts b/api/discord/verify-code.ts
index 9e80bc4b..33c8084c 100644
--- a/api/discord/verify-code.ts
+++ b/api/discord/verify-code.ts
@@ -12,7 +12,9 @@ export default async function handler(req: any, res: any) {
const { verification_code, user_id } = req.body;
if (!verification_code || !user_id) {
- return res.status(400).json({ message: "Missing verification code or user ID" });
+ return res
+ .status(400)
+ .json({ message: "Missing verification code or user ID" });
}
const supabaseUrl = process.env.VITE_SUPABASE_URL;
@@ -35,7 +37,8 @@ export default async function handler(req: any, res: any) {
if (verifyError || !verification) {
return res.status(400).json({
- message: "Invalid or expired verification code. Please try /verify again.",
+ message:
+ "Invalid or expired verification code. Please try /verify again.",
});
}
@@ -50,7 +53,8 @@ export default async function handler(req: any, res: any) {
if (existingLink && existingLink.user_id !== user_id) {
return res.status(400).json({
- message: "This Discord account is already linked to another AeThex account.",
+ message:
+ "This Discord account is already linked to another AeThex account.",
});
}
@@ -63,7 +67,9 @@ export default async function handler(req: any, res: any) {
if (linkError) {
console.error("[Discord Verify] Link creation failed:", linkError);
- return res.status(500).json({ message: "Failed to link Discord account" });
+ return res
+ .status(500)
+ .json({ message: "Failed to link Discord account" });
}
// Delete used verification code
diff --git a/client/components/ArmSwitcher.tsx b/client/components/ArmSwitcher.tsx
index a0d24142..2544413a 100644
--- a/client/components/ArmSwitcher.tsx
+++ b/client/components/ArmSwitcher.tsx
@@ -166,7 +166,6 @@ export default function ArmSwitcher() {
onClose={() => setIsModalOpen(false)}
/>
-
>
);
}
diff --git a/client/components/ArmSwitcherModal.tsx b/client/components/ArmSwitcherModal.tsx
index cf104797..d0da03ac 100644
--- a/client/components/ArmSwitcherModal.tsx
+++ b/client/components/ArmSwitcherModal.tsx
@@ -94,7 +94,8 @@ const ARM_DESCRIPTIONS: Record
/verify
+ /verify
+
+ - 💡 Tip: You can also sign in directly with Discord - on the login page if you're creating a new account. + 💡 Tip: You can also sign in directly with + Discord on the login page if you're creating a new account.