diff --git a/app/signin/page.tsx b/app/signin/page.tsx index 96030519..4a8ac934 100644 --- a/app/signin/page.tsx +++ b/app/signin/page.tsx @@ -1,16 +1,127 @@ "use client"; -import { useEffect } from "react"; 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); - useEffect(() => { - // Redirect to the NextAuth.js sign-in page - router.push("/api/auth/signin"); - }, [router]); + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setIsLoading(true); + setError(null); - return 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}
+ )} + +
+ +
+
+
+
+ ); }