362 lines
13 KiB
HTML
362 lines
13 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Monochrome — Login</title>
|
|
<style>
|
|
*,
|
|
*::before,
|
|
*::after {
|
|
box-sizing: border-box;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
|
|
body {
|
|
font-family:
|
|
'Inter',
|
|
-apple-system,
|
|
BlinkMacSystemFont,
|
|
'Segoe UI',
|
|
Roboto,
|
|
sans-serif;
|
|
background: #0a0a0a;
|
|
color: #e0e0e0;
|
|
min-height: 100vh;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.login-container {
|
|
width: 100%;
|
|
max-width: 380px;
|
|
padding: 2rem;
|
|
}
|
|
|
|
.logo {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 0.75rem;
|
|
margin-bottom: 2.5rem;
|
|
}
|
|
|
|
.logo svg {
|
|
width: 40px;
|
|
height: 40px;
|
|
}
|
|
|
|
.logo span {
|
|
font-size: 1.5rem;
|
|
font-weight: 600;
|
|
letter-spacing: -0.02em;
|
|
color: #fff;
|
|
}
|
|
|
|
.btn {
|
|
width: 100%;
|
|
padding: 0.75rem 1rem;
|
|
border: 1px solid #2a2a2a;
|
|
border-radius: 8px;
|
|
background: #151515;
|
|
color: #e0e0e0;
|
|
font-size: 0.925rem;
|
|
font-family: inherit;
|
|
cursor: pointer;
|
|
transition:
|
|
background 0.15s,
|
|
border-color 0.15s;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.btn:hover {
|
|
background: #1e1e1e;
|
|
border-color: #3a3a3a;
|
|
}
|
|
.btn:disabled {
|
|
opacity: 0.5;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.btn-primary {
|
|
background: #fff;
|
|
color: #0a0a0a;
|
|
border-color: #fff;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
background: #e0e0e0;
|
|
border-color: #e0e0e0;
|
|
}
|
|
|
|
.divider {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 1rem;
|
|
margin: 1.5rem 0;
|
|
color: #555;
|
|
font-size: 0.8rem;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.05em;
|
|
}
|
|
|
|
.divider::before,
|
|
.divider::after {
|
|
content: '';
|
|
flex: 1;
|
|
height: 1px;
|
|
background: #2a2a2a;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.form-group input {
|
|
width: 100%;
|
|
padding: 0.75rem 1rem;
|
|
border: 1px solid #2a2a2a;
|
|
border-radius: 8px;
|
|
background: #151515;
|
|
color: #e0e0e0;
|
|
font-size: 0.925rem;
|
|
font-family: inherit;
|
|
outline: none;
|
|
transition: border-color 0.15s;
|
|
}
|
|
|
|
.form-group input:focus {
|
|
border-color: #555;
|
|
}
|
|
|
|
.error-msg {
|
|
background: #1a0000;
|
|
border: 1px solid #3a1111;
|
|
color: #ff6b6b;
|
|
padding: 0.75rem 1rem;
|
|
border-radius: 8px;
|
|
font-size: 0.85rem;
|
|
margin-bottom: 1rem;
|
|
display: none;
|
|
}
|
|
|
|
.spinner {
|
|
width: 18px;
|
|
height: 18px;
|
|
border: 2px solid transparent;
|
|
border-top-color: currentColor;
|
|
border-radius: 50%;
|
|
animation: spin 0.6s linear infinite;
|
|
display: none;
|
|
}
|
|
|
|
@keyframes spin {
|
|
to {
|
|
transform: rotate(360deg);
|
|
}
|
|
}
|
|
|
|
.google-icon {
|
|
width: 18px;
|
|
height: 18px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-container">
|
|
<div class="logo">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="14.75 14.75 70.5 70.5">
|
|
<g fill="white">
|
|
<path
|
|
d="M38.25 14.75H85.25V61.75H61.75V38.25H38.25ZM14.75 38.25H38.25V61.75H61.75V85.25H14.75Z"
|
|
/>
|
|
</g>
|
|
</svg>
|
|
<span>Monochrome</span>
|
|
</div>
|
|
|
|
<div id="error" class="error-msg"></div>
|
|
|
|
<button id="google-btn" class="btn" onclick="googleSignIn()" style="display:none">
|
|
<svg class="google-icon" viewBox="0 0 24 24">
|
|
<path
|
|
fill="#4285F4"
|
|
d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z"
|
|
/>
|
|
<path
|
|
fill="#34A853"
|
|
d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"
|
|
/>
|
|
<path
|
|
fill="#FBBC05"
|
|
d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"
|
|
/>
|
|
<path
|
|
fill="#EA4335"
|
|
d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"
|
|
/>
|
|
</svg>
|
|
Sign in with Google
|
|
</button>
|
|
|
|
<div class="divider" style="display:none">or</div>
|
|
|
|
<form id="email-form" onsubmit="emailAuth(event)" style="display:none">
|
|
<div class="form-group">
|
|
<input type="email" id="email" placeholder="Email" required autocomplete="email" />
|
|
</div>
|
|
<div class="form-group">
|
|
<input
|
|
type="password"
|
|
id="password"
|
|
placeholder="Password"
|
|
required
|
|
autocomplete="current-password"
|
|
/>
|
|
</div>
|
|
<button type="submit" id="email-btn" class="btn btn-primary">
|
|
<span id="email-btn-text">Sign In</span>
|
|
<span id="email-btn-spinner" class="spinner"></span>
|
|
</button>
|
|
</form>
|
|
</div>
|
|
|
|
<script type="module">
|
|
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js';
|
|
import {
|
|
getAuth,
|
|
GoogleAuthProvider,
|
|
signInWithPopup,
|
|
signInWithEmailAndPassword,
|
|
} from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-auth.js';
|
|
|
|
const STORAGE_KEY = 'monochrome-firebase-config';
|
|
const DEFAULT_CONFIG = {
|
|
apiKey: 'AIzaSyDPU-unAjuLtQJt4IkGS5faG50UCF7lYyA',
|
|
authDomain: 'monochrome-database.firebaseapp.com',
|
|
projectId: 'monochrome-database',
|
|
storageBucket: 'monochrome-database.firebasestorage.app',
|
|
messagingSenderId: '895657412760',
|
|
appId: '1:895657412760:web:e81c5044c7f4e9b799e8ed',
|
|
};
|
|
|
|
// Check for setup_firebase hash import
|
|
const hash = window.location.hash;
|
|
if (hash.startsWith('#setup_firebase=')) {
|
|
try {
|
|
const encoded = hash.split('#setup_firebase=')[1];
|
|
const config = JSON.parse(atob(encoded));
|
|
if (config.apiKey && config.authDomain) {
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(config));
|
|
window.history.replaceState(null, null, '/login');
|
|
}
|
|
} catch (e) {
|
|
console.warn('Failed to import Firebase config from hash:', e);
|
|
}
|
|
}
|
|
|
|
let storedConfig = null;
|
|
try {
|
|
const raw = localStorage.getItem(STORAGE_KEY);
|
|
if (raw) storedConfig = JSON.parse(raw);
|
|
} catch (_) {}
|
|
|
|
// Priority: server-injected env > localStorage > hash-imported > default
|
|
const firebaseConfig = window.__FIREBASE_CONFIG__ || storedConfig || DEFAULT_CONFIG;
|
|
// Sync to localStorage so the app's config.js picks up the same project
|
|
if (window.__FIREBASE_CONFIG__ && !storedConfig) {
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(firebaseConfig));
|
|
}
|
|
const fbApp = initializeApp(firebaseConfig);
|
|
const auth = getAuth(fbApp);
|
|
const provider = new GoogleAuthProvider();
|
|
|
|
// Reveal auth providers based on Firebase project config (non-blocking)
|
|
fetch(`https://www.googleapis.com/identitytoolkit/v3/relyingparty/getProjectConfig?key=${firebaseConfig.apiKey}`)
|
|
.then(res => res.ok ? res.json() : null)
|
|
.then(data => {
|
|
if (!data) return;
|
|
const providers = (data.idpConfig || []).filter(p => p.enabled).map(p => p.provider);
|
|
const hasGoogle = providers.includes('google.com');
|
|
const hasPassword = (data.signIn || {}).allowPasswordSignup !== false;
|
|
if (hasGoogle) document.getElementById('google-btn').style.display = '';
|
|
if (hasPassword) document.getElementById('email-form').style.display = '';
|
|
if (hasGoogle && hasPassword) document.querySelector('.divider').style.display = '';
|
|
})
|
|
.catch(() => {
|
|
// Fallback: show everything if the check fails
|
|
document.getElementById('google-btn').style.display = '';
|
|
document.getElementById('email-form').style.display = '';
|
|
document.querySelector('.divider').style.display = '';
|
|
});
|
|
|
|
function showError(msg) {
|
|
const el = document.getElementById('error');
|
|
el.textContent = msg;
|
|
el.style.display = 'block';
|
|
}
|
|
|
|
function hideError() {
|
|
document.getElementById('error').style.display = 'none';
|
|
}
|
|
|
|
function setLoading(loading) {
|
|
document.getElementById('google-btn').disabled = loading;
|
|
document.getElementById('email-btn').disabled = loading;
|
|
document.getElementById('email-btn-text').style.display = loading ? 'none' : 'inline';
|
|
document.getElementById('email-btn-spinner').style.display = loading ? 'inline-block' : 'none';
|
|
}
|
|
|
|
async function sendTokenToServer(user) {
|
|
const token = await user.getIdToken();
|
|
const res = await fetch('/api/auth/login', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ token }),
|
|
});
|
|
if (!res.ok) {
|
|
const data = await res.json().catch(() => ({}));
|
|
throw new Error(data.error || 'Server authentication failed');
|
|
}
|
|
window.location.href = '/';
|
|
}
|
|
|
|
window.googleSignIn = async function () {
|
|
hideError();
|
|
setLoading(true);
|
|
try {
|
|
const result = await signInWithPopup(auth, provider);
|
|
await sendTokenToServer(result.user);
|
|
} catch (err) {
|
|
if (err.code !== 'auth/popup-closed-by-user') {
|
|
showError(err.message);
|
|
}
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
window.emailAuth = async function (e) {
|
|
e.preventDefault();
|
|
hideError();
|
|
setLoading(true);
|
|
|
|
const email = document.getElementById('email').value;
|
|
const password = document.getElementById('password').value;
|
|
|
|
try {
|
|
const result = await signInWithEmailAndPassword(auth, email, password);
|
|
await sendTokenToServer(result.user);
|
|
} catch (err) {
|
|
showError(err.message);
|
|
setLoading(false);
|
|
}
|
|
};
|
|
</script>
|
|
</body>
|
|
</html>
|