"use client"; import { Egg, Loader2, Tv } from "lucide-react"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { authApi } from "@/lib/api"; import { useStore } from "@/lib/store"; export default function LoginPage() { const router = useRouter(); const { isAuthenticated } = useStore(); const [isLoading, setIsLoading] = useState(false); const [isMounted, setIsMounted] = useState(false); useEffect(() => { setIsMounted(true); }, []); useEffect(() => { if (isAuthenticated) { router.push("/dashboard"); } }, [isAuthenticated, router]); const handlePlexLogin = async () => { setIsLoading(true); try { const response = await authApi.getPlexUrl(); sessionStorage.setItem("plexPinId", response.data.pinId); window.location.href = response.data.authUrl; } catch (error) { toast.error("Failed to initiate Plex login"); console.error(error); setIsLoading(false); } }; if (!isMounted) { return (
Join the flock and get rewarded for your watch time