diff --git a/index.html b/index.html
index 7e74834..0c62589 100644
--- a/index.html
+++ b/index.html
@@ -1013,6 +1013,21 @@
+
+
@@ -1397,8 +1412,9 @@ window.sendMagicLink = async function() {
btn.disabled = true;
btn.innerHTML = ' Sending…';
try {
+ const continueUrl = APP_URL + '?email=' + encodeURIComponent(email);
await sendSignInLinkToEmail(auth, email, {
- url: APP_URL,
+ url: continueUrl,
handleCodeInApp: true
});
localStorage.setItem('emailForSignIn', email);
@@ -1426,9 +1442,12 @@ window.showAuthForm = function() {
// ─────────────────────────────────────────────
onAuthStateChanged(auth, async (user) => {
if (isSignInWithEmailLink(auth, window.location.href)) {
- let email = localStorage.getItem('emailForSignIn');
+ const urlParams = new URLSearchParams(window.location.search);
+ const email = urlParams.get('email') || localStorage.getItem('emailForSignIn');
if (!email) {
- email = window.prompt('Please confirm your email:');
+ showScreen('confirm');
+ document.getElementById('confirm-email-input').focus();
+ return;
}
try {
const result = await signInWithEmailLink(auth, email, window.location.href);
@@ -1451,6 +1470,30 @@ onAuthStateChanged(auth, async (user) => {
}
});
+window.confirmEmailSignIn = async function() {
+ const email = document.getElementById('confirm-email-input').value.trim();
+ const errEl = document.getElementById('confirm-email-error');
+ const btn = document.getElementById('confirm-email-btn');
+ errEl.style.display = 'none';
+ if (!email || !/\S+@\S+\.\S+/.test(email)) {
+ errEl.textContent = 'Please enter a valid email address.';
+ errEl.style.display = 'block';
+ return;
+ }
+ btn.disabled = true;
+ btn.innerHTML = '';
+ try {
+ const result = await signInWithEmailLink(auth, email, window.location.href);
+ window.history.replaceState({}, document.title, APP_URL);
+ await initUser(result.user);
+ } catch(e) {
+ errEl.textContent = 'That email doesn\'t match this sign-in link. Please try again.';
+ errEl.style.display = 'block';
+ btn.disabled = false;
+ btn.innerHTML = 'Sign in';
+ }
+}
+
async function initUser(user) {
currentUser = user;
const userRef = doc(db, 'users', user.uid);
@@ -2053,6 +2096,10 @@ document.getElementById('auth-email').addEventListener('keydown', e => {
if (e.key === 'Enter') sendMagicLink();
});
+document.getElementById('confirm-email-input').addEventListener('keydown', e => {
+ if (e.key === 'Enter') confirmEmailSignIn();
+});
+
document.getElementById('profile-name-input').addEventListener('input', updateProfilePreview);
document.getElementById('profile-avatar-input').addEventListener('input', updateProfilePreview);