From dd24c2bbe9279277573d833ffa6ab42629aae911 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Tue, 11 Nov 2025 17:18:16 +0000 Subject: [PATCH] Create Staff Login page with Google OAuth validation cgen-78509c2a6b2244d699c766ee6f0aeeba --- client/pages/StaffLogin.tsx | 138 ++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 client/pages/StaffLogin.tsx diff --git a/client/pages/StaffLogin.tsx b/client/pages/StaffLogin.tsx new file mode 100644 index 00000000..54cd0b9e --- /dev/null +++ b/client/pages/StaffLogin.tsx @@ -0,0 +1,138 @@ +import { useState, useEffect } from "react"; +import { useNavigate, useLocation } from "react-router-dom"; +import Layout from "@/components/Layout"; +import { Button } from "@/components/ui/button"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { Alert, AlertDescription } from "@/components/ui/alert"; +import { useAuth } from "@/contexts/AuthContext"; +import { useAethexToast } from "@/hooks/use-aethex-toast"; +import LoadingScreen from "@/components/LoadingScreen"; +import { Mail, AlertCircle, Loader2 } from "lucide-react"; + +export default function StaffLogin() { + const navigate = useNavigate(); + const location = useLocation(); + const { signInWithOAuth, user, loading, profile } = useAuth(); + const { error: toastError, info: toastInfo } = useAethexToast(); + const [isSigningIn, setIsSigningIn] = useState(false); + const [error, setError] = useState(null); + + // Redirect if already authenticated and has @aethex.dev email + useEffect(() => { + if (!loading && user && profile) { + const email = user.email || profile.email || ""; + if (email.endsWith("@aethex.dev")) { + toastInfo({ + title: "Already logged in", + description: "Redirecting to staff dashboard...", + }); + navigate("/staff/dashboard", { replace: true }); + } else { + setError("Only @aethex.dev email addresses are allowed"); + } + } + }, [user, profile, loading, navigate, toastInfo]); + + const handleGoogleSignIn = async () => { + setIsSigningIn(true); + setError(null); + try { + await signInWithOAuth("google"); + // Note: Redirect will happen in the useEffect above after auth completes + } catch (err: any) { + const errorMsg = + err?.message || "Failed to sign in with Google. Please try again."; + setError(errorMsg); + toastError({ + title: "Sign in failed", + description: errorMsg, + }); + setIsSigningIn(false); + } + }; + + if (loading) { + return ( + + ); + } + + return ( + +
+ + +
+
+ +
+
+ + Staff Portal + +

+ Internal operations and management dashboard for AeThex staff +

+
+ + + {error && ( + + + + {error} + + + )} + +
+

+ Only staff members with @aethex.dev email addresses can access + this portal +

+ + +
+ +
+

+ This portal is restricted to authorized AeThex staff members +

+
+
+
+
+
+ ); +} + +const Shield = ({ className }: { className: string }) => ( + + + +);