prettify
This commit is contained in:
parent
c1ebce949c
commit
c77507dfe0
2 changed files with 314 additions and 260 deletions
|
|
@ -1617,7 +1617,8 @@ export function initializeSettings(scrobbler, player, api, ui) {
|
||||||
|
|
||||||
// Hide individual fields in the modal
|
// Hide individual fields in the modal
|
||||||
if (pbFromEnv && customPbUrlInput) customPbUrlInput.closest('div[style]').style.display = 'none';
|
if (pbFromEnv && customPbUrlInput) customPbUrlInput.closest('div[style]').style.display = 'none';
|
||||||
if (fbFromEnv && customFirebaseConfigInput) customFirebaseConfigInput.closest('div[style]').style.display = 'none';
|
if (fbFromEnv && customFirebaseConfigInput)
|
||||||
|
customFirebaseConfigInput.closest('div[style]').style.display = 'none';
|
||||||
|
|
||||||
customDbBtn.addEventListener('click', () => {
|
customDbBtn.addEventListener('click', () => {
|
||||||
const pbUrl = localStorage.getItem('monochrome-pocketbase-url') || '';
|
const pbUrl = localStorage.getItem('monochrome-pocketbase-url') || '';
|
||||||
|
|
|
||||||
|
|
@ -1,290 +1,343 @@
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Monochrome — Login</title>
|
<title>Monochrome — Login</title>
|
||||||
<style>
|
<style>
|
||||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
*,
|
||||||
|
*::before,
|
||||||
|
*::after {
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
font-family:
|
||||||
background: #0a0a0a;
|
'Inter',
|
||||||
color: #e0e0e0;
|
-apple-system,
|
||||||
min-height: 100vh;
|
BlinkMacSystemFont,
|
||||||
display: flex;
|
'Segoe UI',
|
||||||
align-items: center;
|
Roboto,
|
||||||
justify-content: center;
|
sans-serif;
|
||||||
}
|
background: #0a0a0a;
|
||||||
|
color: #e0e0e0;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
.login-container {
|
.login-container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 380px;
|
max-width: 380px;
|
||||||
padding: 2rem;
|
padding: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.logo {
|
.logo {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 0.75rem;
|
gap: 0.75rem;
|
||||||
margin-bottom: 2.5rem;
|
margin-bottom: 2.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.logo svg { width: 40px; height: 40px; }
|
.logo svg {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
.logo span {
|
.logo span {
|
||||||
font-size: 1.5rem;
|
font-size: 1.5rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
letter-spacing: -0.02em;
|
letter-spacing: -0.02em;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn {
|
.btn {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 0.75rem 1rem;
|
padding: 0.75rem 1rem;
|
||||||
border: 1px solid #2a2a2a;
|
border: 1px solid #2a2a2a;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
background: #151515;
|
background: #151515;
|
||||||
color: #e0e0e0;
|
color: #e0e0e0;
|
||||||
font-size: 0.925rem;
|
font-size: 0.925rem;
|
||||||
font-family: inherit;
|
font-family: inherit;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background 0.15s, border-color 0.15s;
|
transition:
|
||||||
display: flex;
|
background 0.15s,
|
||||||
align-items: center;
|
border-color 0.15s;
|
||||||
justify-content: center;
|
display: flex;
|
||||||
gap: 0.5rem;
|
align-items: center;
|
||||||
}
|
justify-content: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
.btn:hover { background: #1e1e1e; border-color: #3a3a3a; }
|
.btn:hover {
|
||||||
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
background: #1e1e1e;
|
||||||
|
border-color: #3a3a3a;
|
||||||
|
}
|
||||||
|
.btn:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
.btn-primary {
|
.btn-primary {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
color: #0a0a0a;
|
color: #0a0a0a;
|
||||||
border-color: #fff;
|
border-color: #fff;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-primary:hover { background: #e0e0e0; border-color: #e0e0e0; }
|
.btn-primary:hover {
|
||||||
|
background: #e0e0e0;
|
||||||
|
border-color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
.divider {
|
.divider {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
margin: 1.5rem 0;
|
margin: 1.5rem 0;
|
||||||
color: #555;
|
color: #555;
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
letter-spacing: 0.05em;
|
letter-spacing: 0.05em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.divider::before, .divider::after {
|
.divider::before,
|
||||||
content: '';
|
.divider::after {
|
||||||
flex: 1;
|
content: '';
|
||||||
height: 1px;
|
flex: 1;
|
||||||
background: #2a2a2a;
|
height: 1px;
|
||||||
}
|
background: #2a2a2a;
|
||||||
|
}
|
||||||
|
|
||||||
.form-group { margin-bottom: 1rem; }
|
.form-group {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
.form-group input {
|
.form-group input {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 0.75rem 1rem;
|
padding: 0.75rem 1rem;
|
||||||
border: 1px solid #2a2a2a;
|
border: 1px solid #2a2a2a;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
background: #151515;
|
background: #151515;
|
||||||
color: #e0e0e0;
|
color: #e0e0e0;
|
||||||
font-size: 0.925rem;
|
font-size: 0.925rem;
|
||||||
font-family: inherit;
|
font-family: inherit;
|
||||||
outline: none;
|
outline: none;
|
||||||
transition: border-color 0.15s;
|
transition: border-color 0.15s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-group input:focus { border-color: #555; }
|
.form-group input:focus {
|
||||||
|
border-color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
.error-msg {
|
.error-msg {
|
||||||
background: #1a0000;
|
background: #1a0000;
|
||||||
border: 1px solid #3a1111;
|
border: 1px solid #3a1111;
|
||||||
color: #ff6b6b;
|
color: #ff6b6b;
|
||||||
padding: 0.75rem 1rem;
|
padding: 0.75rem 1rem;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
font-size: 0.85rem;
|
font-size: 0.85rem;
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.spinner {
|
.spinner {
|
||||||
width: 18px;
|
width: 18px;
|
||||||
height: 18px;
|
height: 18px;
|
||||||
border: 2px solid transparent;
|
border: 2px solid transparent;
|
||||||
border-top-color: currentColor;
|
border-top-color: currentColor;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
animation: spin 0.6s linear infinite;
|
animation: spin 0.6s linear infinite;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes spin { to { transform: rotate(360deg); } }
|
@keyframes spin {
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.google-icon {
|
.google-icon {
|
||||||
width: 18px;
|
width: 18px;
|
||||||
height: 18px;
|
height: 18px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="login-container">
|
<div class="login-container">
|
||||||
<div class="logo">
|
<div class="logo">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="14.75 14.75 70.5 70.5">
|
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="14.75 14.75 70.5 70.5">
|
||||||
<g fill="white">
|
<g fill="white">
|
||||||
<path d="M38.25 14.75H85.25V61.75H61.75V38.25H38.25ZM14.75 38.25H38.25V61.75H61.75V85.25H14.75Z" />
|
<path
|
||||||
</g>
|
d="M38.25 14.75H85.25V61.75H61.75V38.25H38.25ZM14.75 38.25H38.25V61.75H61.75V85.25H14.75Z"
|
||||||
</svg>
|
/>
|
||||||
<span>Monochrome</span>
|
</g>
|
||||||
|
</svg>
|
||||||
|
<span>Monochrome</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="error" class="error-msg"></div>
|
||||||
|
|
||||||
|
<button id="google-btn" class="btn" onclick="googleSignIn()">
|
||||||
|
<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">or</div>
|
||||||
|
|
||||||
|
<form id="email-form" onsubmit="emailAuth(event)">
|
||||||
|
<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>
|
</div>
|
||||||
|
|
||||||
<div id="error" class="error-msg"></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';
|
||||||
|
|
||||||
<button id="google-btn" class="btn" onclick="googleSignIn()">
|
const STORAGE_KEY = 'monochrome-firebase-config';
|
||||||
<svg class="google-icon" viewBox="0 0 24 24">
|
const DEFAULT_CONFIG = {
|
||||||
<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"/>
|
apiKey: 'AIzaSyDPU-unAjuLtQJt4IkGS5faG50UCF7lYyA',
|
||||||
<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"/>
|
authDomain: 'monochrome-database.firebaseapp.com',
|
||||||
<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"/>
|
projectId: 'monochrome-database',
|
||||||
<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"/>
|
storageBucket: 'monochrome-database.firebasestorage.app',
|
||||||
</svg>
|
messagingSenderId: '895657412760',
|
||||||
Sign in with Google
|
appId: '1:895657412760:web:e81c5044c7f4e9b799e8ed',
|
||||||
</button>
|
};
|
||||||
|
|
||||||
<div class="divider">or</div>
|
// Check for setup_firebase hash import
|
||||||
|
const hash = window.location.hash;
|
||||||
<form id="email-form" onsubmit="emailAuth(event)">
|
if (hash.startsWith('#setup_firebase=')) {
|
||||||
<div class="form-group">
|
try {
|
||||||
<input type="email" id="email" placeholder="Email" required autocomplete="email" />
|
const encoded = hash.split('#setup_firebase=')[1];
|
||||||
</div>
|
const config = JSON.parse(atob(encoded));
|
||||||
<div class="form-group">
|
if (config.apiKey && config.authDomain) {
|
||||||
<input type="password" id="password" placeholder="Password" required autocomplete="current-password" />
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(config));
|
||||||
</div>
|
window.history.replaceState(null, null, '/login');
|
||||||
<button type="submit" id="email-btn" class="btn btn-primary">
|
}
|
||||||
<span id="email-btn-text">Sign In</span>
|
} catch (e) {
|
||||||
<span id="email-btn-spinner" class="spinner"></span>
|
console.warn('Failed to import Firebase config from hash:', e);
|
||||||
</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;
|
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();
|
|
||||||
|
|
||||||
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 {
|
try {
|
||||||
const result = await signInWithPopup(auth, provider);
|
const raw = localStorage.getItem(STORAGE_KEY);
|
||||||
await sendTokenToServer(result.user);
|
if (raw) storedConfig = JSON.parse(raw);
|
||||||
} catch (err) {
|
} catch (_) {}
|
||||||
if (err.code !== 'auth/popup-closed-by-user') {
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
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);
|
showError(err.message);
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
setLoading(false);
|
};
|
||||||
}
|
</script>
|
||||||
};
|
</body>
|
||||||
|
|
||||||
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>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue