Leogron777's picture
Upload components/Auth.js with huggingface_hub
b653253 verified
Raw History Blame Contribute Delete
5.24 kB
import { useState } from 'react'
import { useFirebase } from './FirebaseProvider'
import { Mail, Lock, Google, Eye, EyeOff } from 'lucide-react'
export default function Auth() {
const [isSignUp, setIsSignUp] = useState(false)
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [showPassword, setShowPassword] = useState(false)
const [error, setError] = useState('')
const [loading, setLoading] = useState(false)
const { signInWithGoogle, signInWithEmail, signUpWithEmail } = useFirebase()
const handleSubmit = async (e) => {
e.preventDefault()
setError('')
setLoading(true)
try {
if (isSignUp) {
await signUpWithEmail(email, password)
} else {
await signInWithEmail(email, password)
}
} catch (error) {
setError(error.message || 'An error occurred')
} finally {
setLoading(false)
}
}
const handleGoogleSignIn = async () => {
setLoading(true)
await signInWithGoogle()
setLoading(false)
}
return (
<div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-primary-50 to-green-50 p-4">
<div className="bg-white rounded-2xl shadow-xl p-8 w-full max-w-md animate-fade-in">
<div className="text-center mb-8">
<h1 className="text-3xl font-bold text-gray-800 mb-2">Social Task Messenger</h1>
<p className="text-gray-600">The world's first encrypted task messenger</p>
<a
href="https://huggingface.co/spaces/akhaliq/anycoder"
target="_blank"
rel="noopener noreferrer"
className="text-primary-600 hover:text-primary-700 text-sm mt-2 inline-block"
>
Built with anycoder
</a>
</div>
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">Email</label>
<div className="relative">
<Mail className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 w-5 h-5" />
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
className="w-full pl-10 pr-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent"
placeholder="Enter your email"
required
/>
</div>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">Password</label>
<div className="relative">
<Lock className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 w-5 h-5" />
<input
type={showPassword ? 'text' : 'password'}
value={password}
onChange={(e) => setPassword(e.target.value)}
className="w-full pl-10 pr-12 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent"
placeholder="Enter your password"
required
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600"
>
{showPassword ? <EyeOff className="w-5 h-5" /> : <Eye className="w-5 h-5" />}
</button>
</div>
</div>
{error && (
<div className="bg-red-50 text-red-600 p-3 rounded-lg text-sm">
{error}
</div>
)}
<button
type="submit"
disabled={loading}
className="w-full bg-primary-600 text-white py-3 rounded-lg font-medium hover:bg-primary-700 transition-colors disabled:opacity-50"
>
{loading ? 'Loading...' : (isSignUp ? 'Sign Up' : 'Sign In')}
</button>
</form>
<div className="mt-6">
<div className="relative">
<div className="absolute inset-0 flex items-center">
<div className="w-full border-t border-gray-300" />
</div>
<div className="relative flex justify-center text-sm">
<span className="px-2 bg-white text-gray-500">Or continue with</span>
</div>
</div>
<button
onClick={handleGoogleSignIn}
disabled={loading}
className="mt-4 w-full flex items-center justify-center gap-3 bg-white border border-gray-300 py-3 rounded-lg font-medium hover:bg-gray-50 transition-colors disabled:opacity-50"
>
<Google className="w-5 h-5" />
Google
</button>
</div>
<div className="mt-6 text-center">
<button
onClick={() => setIsSignUp(!isSignUp)}
className="text-primary-600 hover:text-primary-700 font-medium"
>
{isSignUp ? 'Already have an account? Sign in' : "Don't have an account? Sign up"}
</button>
</div>
</div>
</div>
)
}