-
Notifications
You must be signed in to change notification settings - Fork 1
force users to login to discord after signing in #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bjapeters
wants to merge
1
commit into
main
Choose a base branch
from
brad-discord-oauth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { useEffect, useState } from "react"; | ||
import { Container, Title, Loader, Text, Anchor } from "@mantine/core"; | ||
|
||
export default function DiscordCallback() { | ||
const [status, setStatus] = useState("processing"); | ||
const [message, setMessage] = useState("Connecting Discord..."); | ||
|
||
useEffect(() => { | ||
const handleDiscordCallback = async () => { | ||
const urlParams = new URLSearchParams(window.location.search); | ||
const code = urlParams.get('code'); | ||
const error = urlParams.get('error'); | ||
|
||
if (error) { | ||
setStatus("error"); | ||
setMessage(`Discord connection failed: ${error}`); | ||
return; | ||
} | ||
|
||
if (!code) { | ||
setStatus("error"); | ||
setMessage("No authorization code received from Discord"); | ||
return; | ||
} | ||
|
||
try { | ||
const response = await fetch('/api/auth/discord/exchange-token', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
credentials: 'include', | ||
body: JSON.stringify({ code }) | ||
}); | ||
|
||
const data = await response.json(); | ||
|
||
if (response.ok && data.success) { | ||
setStatus("success"); | ||
setMessage(`Discord connected: ${data.discord_tag}`); | ||
setTimeout(() => { | ||
window.location.href = '/home'; | ||
}, 2000); | ||
} else { | ||
setStatus("error"); | ||
setMessage(data.error || data.message || "Discord connection failed"); | ||
} | ||
} catch (error) { | ||
setStatus("error"); | ||
setMessage("Network error during Discord connection"); | ||
console.error('Discord error:', error); | ||
} | ||
}; | ||
|
||
handleDiscordCallback(); | ||
}, []); | ||
|
||
return ( | ||
<Container size="xs" className="h-full"> | ||
<div className="pt-[40%] text-center"> | ||
{status === "processing" && ( | ||
<> | ||
<Loader size="lg" mb="md" /> | ||
<Title order={3}>{message}</Title> | ||
</> | ||
)} | ||
{status === "success" && ( | ||
<> | ||
<Title order={3} className="text-green-500">Success!</Title> | ||
<Text mt="md">{message}</Text> | ||
<Text mt="sm" size="sm" className="text-gray-400">Redirecting...</Text> | ||
</> | ||
)} | ||
{status === "error" && ( | ||
<> | ||
<Title order={3} className="text-red-500">Connection Failed</Title> | ||
<Text mt="md">{message}</Text> | ||
<Text mt="md"> | ||
<Anchor href="/home">Back to Home</Anchor> | ||
</Text> | ||
</> | ||
)} | ||
</div> | ||
</Container> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,37 @@ | ||
import { Paper, Text, Title, Container, Anchor } from "@mantine/core"; | ||
import { Paper, Text, Title, Container, Anchor, Button, Group, Badge } from "@mantine/core"; | ||
import { useEffect, useState } from "react"; | ||
|
||
export default function HomePage() { | ||
const [user, setUser] = useState(null); | ||
const [loading, setLoading] = useState(true); | ||
|
||
useEffect(() => { | ||
// Check if user is authenticated and fetch their info | ||
const checkAuth = async () => { | ||
try { | ||
const response = await fetch('/api/auth/whoami', { | ||
credentials: 'include' | ||
}); | ||
if (response.ok) { | ||
const userData = await response.json(); | ||
if (userData.loggedIn) { | ||
setUser(userData); | ||
if (!userData.discord) { | ||
window.location.href = '/api/auth/discord/login'; | ||
return; | ||
} | ||
} | ||
} | ||
} catch (error) { | ||
console.error('Error checking auth:', error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
checkAuth(); | ||
}, []); | ||
|
||
return ( | ||
<Container size="sm" py="6rem"> | ||
<Paper p="xl" shadow="xs" className="bg-neutral-800"> | ||
|
@@ -18,9 +49,37 @@ export default function HomePage() { | |
page. | ||
</Text> | ||
|
||
<Text className="text-2xl mt-5">More questions?</Text> | ||
<Text className="text-2xl mt-5">Discord Connection</Text> | ||
|
||
<Text>Visit our helpdesk or email us at <span></span> | ||
{loading ? ( | ||
<Text>Checking connection status...</Text> | ||
) : user && user.loggedIn ? ( | ||
user.discord ? ( | ||
<Paper p="md" className="bg-neutral-700" mb="md"> | ||
<Group> | ||
<div style={{ flex: 1 }}> | ||
<Group spacing="xs"> | ||
<Text weight={500}>{user.discord}</Text> | ||
<Badge color="green" size="sm">Connected</Badge> | ||
</Group> | ||
<Text size="sm" color="dimmed"> | ||
Mentors can reach you via Discord | ||
</Text> | ||
</div> | ||
</Group> | ||
</Paper> | ||
) : ( | ||
<> | ||
<Text mb="sm">Connecting Discord...</Text> | ||
</> | ||
) | ||
) : ( | ||
<Text>Please log in to connect your Discord account.</Text> | ||
)} | ||
|
||
<Text className="text-2xl mt-5">More questions?</Text> | ||
<Text> | ||
Visit our helpdesk or email us at <span></span> | ||
<Anchor href="mailto:[email protected]" target="_blank"> | ||
[email protected] | ||
</Anchor> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
# CORS configuration | ||
FRONTEND_URL = os.environ.get("FRONTEND_URL", "http://localhost:6001") | ||
BACKEND_URL = os.environ.get("BACKEND_URL", "http://127.0.0.1:3001") | ||
ALLOWED_DOMAINS = [FRONTEND_URL] | ||
ALLOWED_DOMAINS = [BACKEND_URL] | ||
|
||
SQLALCHEMY_DATABASE_URI = os.environ.get( | ||
"SQLALCHEMY_DATABASE_URI", "postgresql://postgres:password@database/qstackdb" | ||
|
@@ -24,10 +24,11 @@ | |
AUTH0_DOMAIN = os.environ.get("AUTH0_DOMAIN") | ||
APP_SECRET_KEY = os.environ.get("APP_SECRET_KEY") | ||
MENTOR_PASS = os.environ.get("MENTOR_PASS") | ||
DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID") | ||
DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET") | ||
|
||
ENV = os.environ.get("ENVIRONMENT", "development") | ||
|
||
|
||
AUTH_ADMINS = [ | ||
{"name": "HackMIT", "email": "[email protected]"}, | ||
{"name": "HackMIT", "email": "[email protected]"} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain this