Discord Linking Fixes - Summary of Changes
Overview
All Discord linking flow issues have been identified and fixed. This document summarizes what was broken and what has been repaired.
✅ Fixes Applied
Fix 1: DiscordVerify Auto-Redirect (FIXED)
File: code/client/pages/DiscordVerify.tsx (Line 91-93)
What was broken:
After
/verifycommand in Discord, user clicks linkCode auto-submits successfully
BUT redirected to
/profile/settings(wrong page)User can't see Discord in connections list
What was fixed:
// BEFORE
setTimeout(() => {
navigate("/profile/settings");
}, 3000);
// AFTER
setTimeout(() => {
navigate("/dashboard?tab=connections");
}, 3000);Impact: Users now see the correct connections tab after successful verification
Fix 2: DiscordVerify Button Redirects (FIXED)
File: code/client/pages/DiscordVerify.tsx (Lines 160, 228)
What was broken:
"Go to Settings" button on success screen →
/profile/settings"Cancel" button on input screen →
/profile/settingsBoth sent users to wrong location
What was fixed:
Button 1 (Line 160):
Button 2 (Line 228):
Impact: Buttons now correctly navigate to dashboard/connections
Fix 3: OAuth Callback Error Messages (IMPROVED)
File: code/api/discord/oauth/callback.ts (Lines 105-113)
What was broken:
When session lost, error message was generic: "Please sign in before linking Discord"
No diagnostic information to help debug
Users didn't know what went wrong
What was fixed:
Impact: Better debugging information in server logs when session is lost
📋 Root Cause Analysis
Session Loss During Dashboard OAuth Linking
What happens:
User on
/dashboard?tab=connectionsClicks "Link Discord" button
Redirected to Discord OAuth
User authorizes
Discord redirects back to
/api/discord/oauth/callback?code=...ISSUE: Session cookies not sent with this redirect
Backend can't extract user_id from cookies
User redirected to login
Root cause: One of the following:
Redirect URI not registered in Discord Dev Portal ← MOST LIKELY
Discord doesn't redirect to the correct URL
Causes issues with cookie handling
Browser cookie policy (SameSite=Lax)
Cookies might not be sent in cross-site redirect
Less likely but possible
Domain mismatch
Redirect URI in code uses different domain than Discord portal
E.g.,
localhostvsaethex.dev
Solution: See DISCORD-OAUTH-SETUP-VERIFICATION.md for step-by-step guide to verify Discord Developer Portal settings
🔍 What Still Needs Verification
The session loss issue requires a manual verification step:
CRITICAL: Verify Discord Dev Portal Redirect URI
Go to: https://discord.com/developers/applications
Find: AeThex application
Click: OAuth2
Look for: REDIRECT URLS / REDIRECTS section
Must contain:
https://aethex.dev/api/discord/oauth/callbackIf missing:
Click: Add Redirect
Paste:
https://aethex.dev/api/discord/oauth/callbackClick: Save Changes
Wait 1-2 minutes for changes to propagate
This is required for the Dashboard "Link Discord" button to work!
🧪 Testing the Fixes
Test 1: Discord /verify Command Flow
/verify Command FlowStatus: ✅ FIXED - All redirects now correct
Test 2: Dashboard "Link Discord" Button
Status: ⚠️ DEPENDS ON - Discord Dev Portal configuration
If redirect URI not registered: User redirected to login
Fix: Verify Discord Dev Portal has correct redirect URI registered (see step above)
Test 3: Already Linked Behavior
Status: ✅ WORKING - Bot prevents duplicate links
📚 Documentation Created
DISCORD-LINKING-FLOW-ANALYSIS.md
Complete flow diagrams
Issue breakdown
Root cause analysis
DISCORD-OAUTH-SETUP-VERIFICATION.md ← READ THIS NEXT
Step-by-step Discord Dev Portal verification
Testing procedures
Debugging guide
Troubleshooting for common issues
DISCORD-LINKING-FIXES-APPLIED.md (this file)
Summary of all code changes
What was broken vs fixed
Remaining verification steps
🎯 Next Steps for User
Read:
code/docs/DISCORD-OAUTH-SETUP-VERIFICATION.mdVerify: Discord Developer Portal has correct redirect URI
Test: Both Discord linking flows
Report: Any errors or issues encountered
Environment Variables Required
Already Set ✅
DISCORD_CLIENT_ID=578971245454950421DISCORD_PUBLIC_KEY=...VITE_SUPABASE_URL=...VITE_SUPABASE_ANON_KEY=...
Verify These Are Set ⚠️
DISCORD_CLIENT_SECRET(set in production only)SUPABASE_SERVICE_ROLE(set in production only)VITE_API_BASE(correct domain for your deployment)
Code Changes Summary
code/client/pages/DiscordVerify.tsx
Lines 91-93: Auto-redirect to connections tab
✅ FIXED
code/client/pages/DiscordVerify.tsx
Line 160: Button redirect to connections tab
✅ FIXED
code/client/pages/DiscordVerify.tsx
Line 228: Cancel button redirect to dashboard
✅ FIXED
code/api/discord/oauth/callback.ts
Lines 105-113: Better error messages
✅ IMPROVED
Discord Dev Portal
OAuth2 Redirect URI registration
⚠️ NEEDS VERIFICATION
Issue Resolution Status
Wrong redirect after /verify
✅ FIXED
Update code + deploy
Session lost during OAuth
⚠️ PARTIALLY FIXED
Need Discord Dev Portal verification
Generic error messages
✅ IMPROVED
Better console logging
UI consistency
✅ FIXED
All redirects now go to connections tab
Deployment Instructions
Deploy code changes:
Verify Discord Dev Portal:
Follow steps in DISCORD-OAUTH-SETUP-VERIFICATION.md
Add redirect URI if missing
Wait for propagation
Test thoroughly:
Test /verify flow
Test Dashboard "Link Discord" button
Check session persistence
Monitor logs:
Watch for
[Discord OAuth]messagesShould be clean after successful linking
Related Issues
Session clearing on page load: ✅ FIXED in previous session
Authentication context: ✅ Preserves Supabase session correctly
Cookie handling: ✅ Properly managed by AuthContext
Questions?
Refer to:
DISCORD-OAUTH-SETUP-VERIFICATION.md - Setup & testing
DISCORD-LINKING-FLOW-ANALYSIS.md - Architecture & flow diagrams
Browser console - Look for
[Discord OAuth]debug messagesServer logs - Look for authentication errors
Last updated
