1+ "use client" ;
2+ import { useState } from "react" ;
3+ import { signInWithGoogle } from "@/lib/firebase/auth" ;
4+ import { useRouter } from "next/navigation" ;
5+
6+ export default function AuthPage ( ) {
7+ const [ error , setError ] = useState < string | null > ( null ) ;
8+ const [ loading , setLoading ] = useState ( false ) ;
9+ const router = useRouter ( ) ;
10+
11+ const handleLoginWithGoogle = async ( ) => {
12+ setLoading ( true ) ;
13+ setError ( null ) ;
14+ try {
15+ const result = await signInWithGoogle ( ) ;
16+ const user = result ?. user ;
17+
18+ if ( user ) {
19+ const idToken = await user . getIdToken ( ) ;
20+ document . cookie = `__session=${ idToken } ; path=/; ` ;
21+ console . log ( "User logged in:" , user ) ;
22+ console . log ( "token stored in cookie:" , idToken ) ;
23+ }
24+ if ( result ?. isAdmin ) {
25+ router . push ( "/" ) ;
26+ }
27+ } catch ( err ) {
28+ console . error ( "Failed to log in with Google:" , err ) ;
29+ setError ( "Failed to log in. Please try again." ) ;
30+ } finally {
31+ setLoading ( false ) ;
32+ }
33+ } ;
34+
35+ return (
36+ < div className = "min-h-screen bg-gradient-to-br from-blue-50 via-white to-blue-100 flex items-center justify-center p-4 relative overflow-hidden" >
37+ { /* Subtle background decorations */ }
38+ < div className = "absolute top-20 left-10 w-32 h-32 bg-blue-200 rounded-full opacity-10 blur-3xl" > </ div >
39+ < div className = "absolute bottom-20 right-10 w-40 h-40 bg-blue-300 rounded-full opacity-15 blur-3xl" > </ div >
40+ < div className = "absolute top-1/2 left-1/4 w-24 h-24 bg-blue-400 rounded-full opacity-10 blur-2xl" > </ div >
41+
42+ < div className = "relative z-10 w-full max-w-md" >
43+ { /* Main card */ }
44+ < div className = "bg-white/80 backdrop-blur-sm rounded-3xl shadow-xl border border-blue-100 p-8 transform hover:scale-105 transition-all duration-300" >
45+ { /* Header */ }
46+ < div className = "text-center mb-8" >
47+ < div className = "w-16 h-16 bg-gradient-to-br from-blue-500 to-blue-700 rounded-2xl flex items-center justify-center mx-auto mb-4 transform rotate-12" >
48+ < svg
49+ className = "w-8 h-8 text-white"
50+ fill = "none"
51+ stroke = "currentColor"
52+ viewBox = "0 0 24 24"
53+ >
54+ < path
55+ strokeLinecap = "round"
56+ strokeLinejoin = "round"
57+ strokeWidth = { 2 }
58+ d = "M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"
59+ />
60+ </ svg >
61+ </ div >
62+ < h2 className = "text-3xl font-bold bg-gradient-to-r from-blue-600 to-blue-800 bg-clip-text text-transparent" >
63+ Welcome
64+ </ h2 >
65+ < p className = "text-blue-600 mt-2 font-medium" >
66+ Sign in to continue your journey
67+ </ p >
68+ </ div >
69+
70+ { /* Google Login Button */ }
71+ < button
72+ onClick = { handleLoginWithGoogle }
73+ disabled = { loading }
74+ aria-label = "Login with Google"
75+ type = "button"
76+ className = "group relative w-full p-2 bg-white border-2 border-blue-200 rounded-2xl shadow-lg hover:shadow-xl transform hover:scale-105 transition-all duration-300 focus:outline-none focus:ring-4 focus:ring-blue-300 focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed disabled:transform-none"
77+ >
78+ < div className = "flex items-center justify-center space-x-3" >
79+ { loading ? (
80+ < >
81+ < div className = "w-6 h-6 border-2 border-blue-300 border-t-blue-600 rounded-full animate-spin" > </ div >
82+ < span className = "text-lg font-semibold text-blue-700" >
83+ Signing you in...
84+ </ span >
85+ </ >
86+ ) : (
87+ < >
88+ < svg
89+ xmlns = "http://www.w3.org/2000/svg"
90+ x = "0px"
91+ y = "0px"
92+ width = "30"
93+ height = "30"
94+ viewBox = "0 0 48 48"
95+ >
96+ < path
97+ fill = "#fbc02d"
98+ d = "M43.611,20.083H42V20H24v8h11.303c-1.649,4.657-6.08,8-11.303,8c-6.627,0-12-5.373-12-12 s5.373-12,12-12c3.059,0,5.842,1.154,7.961,3.039l5.657-5.657C34.046,6.053,29.268,4,24,4C12.955,4,4,12.955,4,24s8.955,20,20,20 s20-8.955,20-20C44,22.659,43.862,21.35,43.611,20.083z"
99+ > </ path >
100+ < path
101+ fill = "#e53935"
102+ d = "M6.306,14.691l6.571,4.819C14.655,15.108,18.961,12,24,12c3.059,0,5.842,1.154,7.961,3.039 l5.657-5.657C34.046,6.053,29.268,4,24,4C16.318,4,9.656,8.337,6.306,14.691z"
103+ > </ path >
104+ < path
105+ fill = "#4caf50"
106+ d = "M24,44c5.166,0,9.86-1.977,13.409-5.192l-6.19-5.238C29.211,35.091,26.715,36,24,36 c-5.202,0-9.619-3.317-11.283-7.946l-6.522,5.025C9.505,39.556,16.227,44,24,44z"
107+ > </ path >
108+ < path
109+ fill = "#1565c0"
110+ d = "M43.611,20.083L43.595,20L42,20H24v8h11.303c-0.792,2.237-2.231,4.166-4.087,5.571 c0.001-0.001,0.002-0.001,0.003-0.002l6.19,5.238C36.971,39.205,44,34,44,24C44,22.659,43.862,21.35,43.611,20.083z"
111+ > </ path >
112+ </ svg >
113+
114+ < span className = "text-lg font-semibold text-gray-700 group-hover:text-blue-700 transition-colors" >
115+ Continue with Google
116+ </ span >
117+ </ >
118+ ) }
119+ </ div >
120+
121+ { /* Hover effect overlay */ }
122+ < div className = "absolute inset-0 bg-gradient-to-r from-blue-50 to-blue-100 rounded-2xl opacity-0 group-hover:opacity-100 transition-opacity duration-300 -z-10" > </ div >
123+ </ button >
124+
125+ { /* Error message */ }
126+ { error && (
127+ < div className = "mt-6 p-4 bg-red-50 border border-red-200 rounded-xl" >
128+ < p className = "text-red-600 text-sm text-center font-medium" >
129+ { error }
130+ </ p >
131+ </ div >
132+ ) }
133+ </ div >
134+
135+ { /* Footer text */ }
136+ < p className = "text-center text-blue-500 text-sm mt-6 font-medium" >
137+ Secure authentication powered by Google
138+ </ p >
139+ < p className = "text-center text-orange-500 text-sm mt-6 font-medium" >
140+ Sign in with pkd skp mail
141+ </ p >
142+ </ div >
143+ </ div >
144+ ) ;
145+ }
0 commit comments