AeThex-OS/temp-forge-extract/aethex-forge-main/client/pages/RobloxCallback.tsx
MrPiglr b3c308b2c8 Add functional marketplace modules, bottom nav bar, root terminal, arcade games
- ModuleManager: Central tracking for installed marketplace modules
- DataAnalyzerWidget: Real-time CPU/RAM/Battery/Storage widget (unlocked by Data Analyzer module)
- BottomNavBar: Navigation bar for Projects/Chat/Marketplace/Settings
- RootShell: Real root command execution utility
- TerminalActivity: Full root shell with neofetch, sysinfo, real Linux commands
- Terminal Pro module: Adds aliases (ll, la, h), command history
- ArcadeActivity + SnakeGame: Pixel Arcade module unlocks retro games
- fade_in/fade_out animations for smooth transitions
2026-02-18 22:03:50 -07:00

101 lines
3.1 KiB
TypeScript

import { useEffect } from "react";
const API_BASE = import.meta.env.VITE_API_BASE || "";
import { useNavigate, useSearchParams } from "react-router-dom";
import LoadingScreen from "@/components/LoadingScreen";
import { useAuth } from "@/contexts/AuthContext";
import { useAethexToast } from "@/hooks/use-aethex-toast";
export default function RobloxCallback() {
const navigate = useNavigate();
const [searchParams] = useSearchParams();
const { user, loading } = useAuth();
const { error: toastError } = useAethexToast();
useEffect(() => {
const handleCallback = async () => {
try {
const code = searchParams.get("code");
const state = searchParams.get("state");
const error = searchParams.get("error");
const errorDescription = searchParams.get("error_description");
if (error) {
toastError({
title: "Roblox OAuth Error",
description: errorDescription || error,
});
navigate("/login");
return;
}
if (!code) {
toastError({
title: "Invalid Roblox callback",
description: "No authorization code received",
});
navigate("/login");
return;
}
// Exchange code for Roblox user info via backend
const response = await fetch(`${API_BASE}/api/roblox/oauth/callback`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ code, state }),
});
if (!response.ok) {
const errorData = await response.json();
toastError({
title: "Authentication failed",
description:
errorData.error || "Could not authenticate with Roblox",
});
navigate("/login");
return;
}
const data = await response.json();
// If user is already authenticated, link the Roblox account
if (user && data.roblox_user_id) {
await fetch(`${API_BASE}/api/user/link-roblox`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
roblox_user_id: data.roblox_user_id,
roblox_username: data.roblox_username,
}),
});
navigate("/dashboard?tab=connections");
return;
}
// Otherwise, redirect to onboarding with Roblox data
const nextUrl = state && state.startsWith("/") ? state : "/onboarding";
navigate(`${nextUrl}?roblox_id=${data.roblox_user_id}`);
} catch (err: any) {
console.error("Roblox callback error:", err);
toastError({
title: "Callback processing failed",
description: err?.message || "An error occurred",
});
navigate("/login");
}
};
if (!loading) {
handleCallback();
}
}, [searchParams, user, loading, navigate, toastError]);
return (
<LoadingScreen
message="Authenticating with Roblox..."
showProgress={true}
duration={3000}
/>
);
}