diff --git a/app/layout.tsx b/app/layout.tsx index 2838ddd..ceb025d 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,7 +1,7 @@ import type { Metadata } from "next"; import { Geist, Geist_Mono } from "next/font/google"; import "./globals.css"; - +import BottomNavBar from "@/components/bottomNavbar"; const geistSans = Geist({ variable: "--font-geist-sans", subsets: ["latin"], @@ -28,6 +28,9 @@ export default function RootLayout({ className={`${geistSans.variable} ${geistMono.variable} antialiased`} > {children} + + + ); diff --git a/app/login/page.tsx b/app/login/page.tsx index 68abc37..5e8b568 100644 --- a/app/login/page.tsx +++ b/app/login/page.tsx @@ -1,38 +1,148 @@ "use client"; -import { useState } from 'react'; -import { signInWithGoogle } from '@/lib/firebase/auth'; - -export default function LoginPage() { - const [loading, setLoading] = useState(false); - const [error, setError] = useState(''); - - const handleLoginWithGoogle = async () => { - setLoading(true); - setError(''); - try { - await signInWithGoogle(); - } catch (err: any) { - if (err.code === 'auth/cancelled-popup-request' || err.code === 'auth/popup-closed-by-user') { - setError('Login was cancelled. Please try again.'); - } else { - setError('Login failed. Please try again.'); - } - } finally { - setLoading(false); - } - }; - - return ( -
- - {error &&
{error}
} +import { useState } from "react"; +import { signInWithGoogle } from "@/lib/firebase/auth"; +import { useRouter } from "next/navigation"; + +export default function AuthPage() { + const [error, setError] = useState(null); + const [loading, setLoading] = useState(false); + const router = useRouter(); + + const handleLoginWithGoogle = async () => { + setLoading(true); + setError(null); + try { + const result = await signInWithGoogle(); + const user = result?.user; + + if (user) { + const idToken = await user.getIdToken(); + document.cookie = `__session=${idToken}; path=/; `; + console.log("User logged in:", user); + console.log("token stored in cookie:", idToken); + } + if (result?.isAdmin) { + router.push("/admin"); + } else { + router.push("/"); + } + } catch (err) { + console.error("Failed to log in with Google:", err); + setError( + err instanceof Error ? err.message : "Failed to log in with Google" + ); + } finally { + setLoading(false); + } + }; + + return ( +
+ {/* Subtle background decorations */} +
+
+
+ +
+ {/* Main card */} +
+ {/* Header */} +
+
+ + + +
+

+ Welcome +

+

+ Sign in to continue your journey +

+
+ + {/* Google Login Button */} + + + {/* Error message */} + {error && ( +
+

+ {error} +

+
+ )}
- ); -} + + {/* Footer text */} +

+ Secure authentication powered by Google +

+ +
+
+ ); +} \ No newline at end of file diff --git a/app/page.tsx b/app/page.tsx index ea7041a..1d459fa 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -41,7 +41,7 @@ export default function Home() {
- + {/* */}
diff --git a/components/Navbar.tsx b/components/Navbar.tsx index 22a7b56..3613cf3 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -5,6 +5,7 @@ import Link from "next/link"; import { onAuthStateChanged } from "@/lib/firebase/auth"; import { signOut, getAuth, User } from "firebase/auth"; // Adjust the import path based on your Firebase setup import { useRouter } from "next/navigation"; +import { ArrowLeftIcon} from "lucide-react"; const Navbar = () => { const [user, setUser] = useState(null); @@ -31,9 +32,17 @@ const Navbar = () => { return (