import { useEffect, useState } from "react"; import { getAuthUrl, handleAuthCallback } from "../../api/client.js"; interface LoginPageProps { onLogin: () => void; } export const LoginPage = ({ onLogin }: LoginPageProps): React.JSX.Element => { const [authUrl, setAuthUrl] = useState(null); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { // Handle OAuth callback const params = new URLSearchParams(window.location.search); const code = params.get("code"); if (code) { setIsLoading(true); handleAuthCallback(code) .then(() => { window.history.replaceState({}, "", "/"); onLogin(); }) .catch((err: unknown) => { setError(err instanceof Error ? err.message : "Authentication failed"); setIsLoading(false); }); return; } // Fetch the Discord OAuth URL getAuthUrl() .then((url) => { setAuthUrl(url); setIsLoading(false); }) .catch(() => { setError("Failed to load authentication URL"); setIsLoading(false); }); }, [onLogin]); if (isLoading) { return (

Loading...

); } if (error) { return (

{error}

); } return (

⚔️ Elysium

An idle fantasy RPG. Hire adventurers, defeat bosses, and ascend to glory.

Login with Discord

Your progress is saved to your Discord account and shareable with others!

); };