Spaces:
Running
Running
File size: 21,000 Bytes
1f8e246 | 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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Firebase Authentication</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Firebase SDK -->
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-auth.js"></script>
<style>
.bg-gradient-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.input-focus:focus {
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}
.btn-google {
background-color: #4285F4;
transition: all 0.3s;
}
.btn-google:hover {
background-color: #357ae8;
transform: translateY(-2px);
}
.btn-apple {
background-color: #000000;
transition: all 0.3s;
}
.btn-apple:hover {
background-color: #333333;
transform: translateY(-2px);
}
.btn-primary {
background-color: #667eea;
transition: all 0.3s;
}
.btn-primary:hover {
background-color: #5a6fd1;
transform: translateY(-2px);
}
.link-primary {
color: #667eea;
transition: all 0.2s;
}
.link-primary:hover {
color: #5a6fd1;
text-decoration: underline;
}
.auth-container {
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}
.divider {
display: flex;
align-items: center;
text-align: center;
color: #9CA3AF;
}
.divider::before, .divider::after {
content: "";
flex: 1;
border-bottom: 1px solid #E5E7EB;
}
.divider::before {
margin-right: 1rem;
}
.divider::after {
margin-left: 1rem;
}
.input-error {
border-color: #EF4444;
}
.error-message {
color: #EF4444;
font-size: 0.875rem;
margin-top: 0.25rem;
}
</style>
</head>
<body class="bg-gray-100 min-h-screen flex items-center justify-center p-4">
<div class="auth-container bg-white rounded-xl overflow-hidden w-full max-w-md">
<div class="bg-gradient-primary py-6 px-8 text-center">
<h1 class="text-2xl font-bold text-white">Welcome Back</h1>
<p class="text-white opacity-90 mt-2">Sign in to access your account</p>
</div>
<div class="px-8 py-6">
<!-- Social Auth Buttons -->
<div class="space-y-4">
<button id="googleSignIn" class="btn-google text-white w-full py-2 rounded-lg flex items-center justify-center">
<i class="fab fa-google mr-3"></i>
Continue with Google
</button>
<button id="appleSignIn" class="btn-apple text-white w-full py-2 rounded-lg flex items-center justify-center">
<i class="fab fa-apple mr-3"></i>
Continue with Apple
</button>
</div>
<!-- Divider -->
<div class="my-6">
<div class="divider">OR</div>
</div>
<!-- Email/Password Form -->
<form id="emailSignInForm" class="space-y-4">
<div>
<label for="email" class="block text-sm font-medium text-gray-700 mb-1">Email</label>
<input type="email" id="email" name="email" required
class="w-full px-4 py-2 border rounded-lg input-focus focus:outline-none">
<p id="emailError" class="error-message hidden"></p>
</div>
<div>
<label for="password" class="block text-sm font-medium text-gray-700 mb-1">Password</label>
<input type="password" id="password" name="password" required
class="w-full px-4 py-2 border rounded-lg input-focus focus:outline-none">
<p id="passwordError" class="error-message hidden"></p>
</div>
<div class="flex items-center justify-between">
<div class="flex items-center">
<input type="checkbox" id="rememberMe" class="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded">
<label for="rememberMe" class="ml-2 block text-sm text-gray-700">Remember me</label>
</div>
<button type="button" id="forgotPassword" class="text-sm link-primary">Forgot password?</button>
</div>
<button type="submit" class="btn-primary text-white w-full py-2 rounded-lg">
Sign In
</button>
</form>
<!-- Sign Up Link -->
<div class="mt-6 text-center">
<p class="text-gray-600">Don't have an account?
<button id="signUpLink" class="link-primary font-medium">Sign up</button>
</p>
</div>
</div>
</div>
<!-- Forgot Password Modal -->
<div id="forgotPasswordModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden">
<div class="bg-white rounded-lg p-6 max-w-md w-full mx-4">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-semibold">Reset Password</h3>
<button id="closeForgotPassword" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<p class="text-gray-600 mb-4">Enter your email address and we'll send you a link to reset your password.</p>
<form id="forgotPasswordForm" class="space-y-4">
<div>
<label for="resetEmail" class="block text-sm font-medium text-gray-700 mb-1">Email</label>
<input type="email" id="resetEmail" name="resetEmail" required
class="w-full px-4 py-2 border rounded-lg input-focus focus:outline-none">
<p id="resetEmailError" class="error-message hidden"></p>
</div>
<button type="submit" class="btn-primary text-white w-full py-2 rounded-lg">
Send Reset Link
</button>
</form>
</div>
</div>
<!-- Sign Up Modal -->
<div id="signUpModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden">
<div class="bg-white rounded-lg p-6 max-w-md w-full mx-4">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-semibold">Create Account</h3>
<button id="closeSignUp" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<form id="signUpForm" class="space-y-4">
<div>
<label for="signupName" class="block text-sm font-medium text-gray-700 mb-1">Full Name</label>
<input type="text" id="signupName" name="signupName" required
class="w-full px-4 py-2 border rounded-lg input-focus focus:outline-none">
<p id="nameError" class="error-message hidden"></p>
</div>
<div>
<label for="signupEmail" class="block text-sm font-medium text-gray-700 mb-1">Email</label>
<input type="email" id="signupEmail" name="signupEmail" required
class="w-full px-4 py-2 border rounded-lg input-focus focus:outline-none">
<p id="signupEmailError" class="error-message hidden"></p>
</div>
<div>
<label for="signupPassword" class="block text-sm font-medium text-gray-700 mb-1">Password</label>
<input type="password" id="signupPassword" name="signupPassword" required
class="w-full px-4 py-2 border rounded-lg input-focus focus:outline-none">
<p id="signupPasswordError" class="error-message hidden"></p>
</div>
<div>
<label for="signupConfirmPassword" class="block text-sm font-medium text-gray-700 mb-1">Confirm Password</label>
<input type="password" id="signupConfirmPassword" name="signupConfirmPassword" required
class="w-full px-4 py-2 border rounded-lg input-focus focus:outline-none">
<p id="confirmPasswordError" class="error-message hidden"></p>
</div>
<div class="flex items-center">
<input type="checkbox" id="terms" name="terms" required
class="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded">
<label for="terms" class="ml-2 block text-sm text-gray-700">
I agree to the <a href="#" class="link-primary">Terms of Service</a> and <a href="#" class="link-primary">Privacy Policy</a>
</label>
</div>
<button type="submit" class="btn-primary text-white w-full py-2 rounded-lg">
Create Account
</button>
</form>
</div>
</div>
<!-- Success Toast -->
<div id="successToast" class="fixed bottom-4 right-4 bg-green-500 text-white px-4 py-2 rounded-lg shadow-lg hidden flex items-center">
<i class="fas fa-check-circle mr-2"></i>
<span id="successMessage"></span>
</div>
<!-- Error Toast -->
<div id="errorToast" class="fixed bottom-4 right-4 bg-red-500 text-white px-4 py-2 rounded-lg shadow-lg hidden flex items-center">
<i class="fas fa-exclamation-circle mr-2"></i>
<span id="errorMessage"></span>
</div>
<script>
// Firebase Configuration (Replace with your actual config)
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_AUTH_DOMAIN",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_STORAGE_BUCKET",
messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
appId: "YOUR_APP_ID"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const auth = firebase.auth();
// DOM Elements
const emailSignInForm = document.getElementById('emailSignInForm');
const googleSignInBtn = document.getElementById('googleSignIn');
const appleSignInBtn = document.getElementById('appleSignIn');
const forgotPasswordBtn = document.getElementById('forgotPassword');
const forgotPasswordModal = document.getElementById('forgotPasswordModal');
const closeForgotPasswordBtn = document.getElementById('closeForgotPassword');
const forgotPasswordForm = document.getElementById('forgotPasswordForm');
const signUpLink = document.getElementById('signUpLink');
const signUpModal = document.getElementById('signUpModal');
const closeSignUpBtn = document.getElementById('closeSignUp');
const signUpForm = document.getElementById('signUpForm');
const successToast = document.getElementById('successToast');
const errorToast = document.getElementById('errorToast');
// Event Listeners
emailSignInForm.addEventListener('submit', handleEmailSignIn);
googleSignInBtn.addEventListener('click', handleGoogleSignIn);
appleSignInBtn.addEventListener('click', handleAppleSignIn);
forgotPasswordBtn.addEventListener('click', () => toggleModal(forgotPasswordModal));
closeForgotPasswordBtn.addEventListener('click', () => toggleModal(forgotPasswordModal));
forgotPasswordForm.addEventListener('submit', handleForgotPassword);
signUpLink.addEventListener('click', () => toggleModal(signUpModal));
closeSignUpBtn.addEventListener('click', () => toggleModal(signUpModal));
signUpForm.addEventListener('submit', handleSignUp);
// Functions
function toggleModal(modal) {
modal.classList.toggle('hidden');
modal.classList.toggle('flex');
}
function showToast(message, isSuccess = true) {
const toast = isSuccess ? successToast : errorToast;
const messageElement = isSuccess ? document.getElementById('successMessage') : document.getElementById('errorMessage');
messageElement.textContent = message;
toast.classList.remove('hidden');
toast.classList.add('flex');
setTimeout(() => {
toast.classList.remove('flex');
toast.classList.add('hidden');
}, 5000);
}
function clearErrors(formId) {
const form = document.getElementById(formId);
const errorMessages = form.querySelectorAll('.error-message');
const inputs = form.querySelectorAll('input');
errorMessages.forEach(el => {
el.classList.add('hidden');
el.textContent = '';
});
inputs.forEach(input => {
input.classList.remove('input-error');
});
}
function showError(inputId, message) {
const input = document.getElementById(inputId);
const errorElement = document.getElementById(`${inputId}Error`);
input.classList.add('input-error');
errorElement.textContent = message;
errorElement.classList.remove('hidden');
}
// Auth Handlers
async function handleEmailSignIn(e) {
e.preventDefault();
clearErrors('emailSignInForm');
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
const rememberMe = document.getElementById('rememberMe').checked;
try {
if (rememberMe) {
await auth.setPersistence(firebase.auth.Auth.Persistence.LOCAL);
} else {
await auth.setPersistence(firebase.auth.Auth.Persistence.SESSION);
}
await auth.signInWithEmailAndPassword(email, password);
showToast('Signed in successfully!');
// Redirect or update UI as needed
} catch (error) {
console.error('Sign in error:', error);
switch (error.code) {
case 'auth/invalid-email':
showError('email', 'Please enter a valid email address');
break;
case 'auth/user-disabled':
showError('email', 'This account has been disabled');
break;
case 'auth/user-not-found':
showError('email', 'No account found with this email');
break;
case 'auth/wrong-password':
showError('password', 'Incorrect password');
break;
default:
showToast(error.message, false);
}
}
}
async function handleGoogleSignIn() {
const provider = new firebase.auth.GoogleAuthProvider();
try {
await auth.signInWithPopup(provider);
showToast('Signed in with Google successfully!');
// Redirect or update UI as needed
} catch (error) {
console.error('Google sign in error:', error);
showToast(error.message, false);
}
}
async function handleAppleSignIn() {
const provider = new firebase.auth.OAuthProvider('apple.com');
try {
await auth.signInWithPopup(provider);
showToast('Signed in with Apple successfully!');
// Redirect or update UI as needed
} catch (error) {
console.error('Apple sign in error:', error);
showToast(error.message, false);
}
}
async function handleForgotPassword(e) {
e.preventDefault();
clearErrors('forgotPasswordForm');
const email = document.getElementById('resetEmail').value;
try {
await auth.sendPasswordResetEmail(email);
showToast('Password reset email sent. Check your inbox.');
toggleModal(forgotPasswordModal);
} catch (error) {
console.error('Password reset error:', error);
if (error.code === 'auth/invalid-email') {
showError('resetEmail', 'Please enter a valid email address');
} else if (error.code === 'auth/user-not-found') {
showError('resetEmail', 'No account found with this email');
} else {
showToast(error.message, false);
}
}
}
async function handleSignUp(e) {
e.preventDefault();
clearErrors('signUpForm');
const name = document.getElementById('signupName').value;
const email = document.getElementById('signupEmail').value;
const password = document.getElementById('signupPassword').value;
const confirmPassword = document.getElementById('signupConfirmPassword').value;
// Basic validation
if (password !== confirmPassword) {
showError('signupConfirmPassword', 'Passwords do not match');
return;
}
if (password.length < 6) {
showError('signupPassword', 'Password must be at least 6 characters');
return;
}
try {
const userCredential = await auth.createUserWithEmailAndPassword(email, password);
await userCredential.user.updateProfile({ displayName: name });
showToast('Account created successfully!');
toggleModal(signUpModal);
// You might want to send email verification here
// await userCredential.user.sendEmailVerification();
} catch (error) {
console.error('Sign up error:', error);
switch (error.code) {
case 'auth/email-already-in-use':
showError('signupEmail', 'This email is already in use');
break;
case 'auth/invalid-email':
showError('signupEmail', 'Please enter a valid email address');
break;
case 'auth/weak-password':
showError('signupPassword', 'Password should be at least 6 characters');
break;
default:
showToast(error.message, false);
}
}
}
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=piloteo/firebase-sample" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |