fix: enhance email verification protection by ensuring DOM manipulation only occurs in the browser

This commit is contained in:
Rotimi Best
2025-12-04 00:00:48 +01:00
parent 25d1a8d710
commit 964c036252
@@ -189,6 +189,7 @@
} }
// Add global CSS to prevent any missed interactions // Add global CSS to prevent any missed interactions
if (document) {
const style = document.createElement('style'); const style = document.createElement('style');
style.id = 'email-verification-protection'; style.id = 'email-verification-protection';
style.textContent = ` style.textContent = `
@@ -204,16 +205,19 @@
`; `;
document.head.appendChild(style); document.head.appendChild(style);
} }
}
function updateBodyClass() { function updateBodyClass() {
if (browser) { if (!browser) {
return;
}
if ($profile.is_email_verified) { if ($profile.is_email_verified) {
document.body.classList.add('email-verified'); document.body.classList.add('email-verified');
} else { } else {
document.body.classList.remove('email-verified'); document.body.classList.remove('email-verified');
} }
} }
}
const sendVerificationCode = async () => { const sendVerificationCode = async () => {
if (isSent) return; if (isSent) return;
@@ -256,13 +260,15 @@
if (domObserver) domObserver.disconnect(); if (domObserver) domObserver.disconnect();
// Clean up protection styles // Clean up protection styles
const style = document.getElementById('email-verification-protection'); if (browser) {
const style = document?.getElementById('email-verification-protection');
if (style) style.remove(); if (style) style.remove();
}
}); });
$: open = Boolean(!$profile.is_email_verified && !!$profile.id && !!$currentOrg.id); $: open = Boolean(!$profile.is_email_verified && !!$profile.id && !!$currentOrg.id);
$: open && sendVerificationCode(); $: open && sendVerificationCode();
$: updateBodyClass(); $: if (browser) updateBodyClass();
// Console warning for developers trying to bypass // Console warning for developers trying to bypass
$: if (browser && !$profile.is_email_verified && $profile.id) { $: if (browser && !$profile.is_email_verified && $profile.id) {