"use client"; import { signIn } from "next-auth/react"; import { useRouter } from "next/navigation"; import { useState } from "react"; export default function SignIn() { const router = useRouter(); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); setError(null); try { const formData = new FormData(e.currentTarget); const email = formData.get("email"); const password = formData.get("password"); const result = await signIn("keycloak", { email, password, redirect: false, }); if (result?.error) { setError("Invalid credentials"); return; } // Initialize folders after successful login try { const response = await fetch('/api/nextcloud/status'); if (!response.ok) { throw new Error('Failed to fetch Nextcloud folders'); } const data = await response.json(); const folders = data.folders || []; // Cache the folders in localStorage for immediate access in Pages localStorage.setItem('nextcloud_folders', JSON.stringify({ folders, timestamp: Date.now() })); } catch (error) { console.error('Error initializing folders:', error); // Continue with navigation even if folder initialization fails } router.push("/"); } catch (error) { setError("An error occurred during sign in"); console.error("Sign in error:", error); } finally { setIsLoading(false); } }; return (

Sign in to your account

{error && (
{error}
)}
); }