Spaces:
Running
Running
File size: 5,239 Bytes
b653253 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | 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>
)
} |