From 6bb6821d391e0750b21f693eb6bdbbaca63be702 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Thu, 29 Sep 2022 13:02:09 -0400 Subject: [PATCH] Don't use cookie when logged in. --- undercover/templates/writing.jinja2 | 30 ++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/undercover/templates/writing.jinja2 b/undercover/templates/writing.jinja2 index bcef9b1..ba5b2a0 100644 --- a/undercover/templates/writing.jinja2 +++ b/undercover/templates/writing.jinja2 @@ -10,20 +10,24 @@ window.scrollTo(0, document.body.scrollHeight); {% endif %} - if (window.location.search.includes("reset=true")) { - window.history.pushState({}, document.title, window.location.pathname); - return; - } - decodeURIComponent(document.cookie).split(';').forEach(cookie => { - [id, value] = cookie.trim().split('=') - if (!id || !value) { - return + {% if not username %} + if (window.location.search.includes("reset=true")) { + window.history.pushState({}, document.title, window.location.pathname); + return; } - const e = document.getElementById(id) - if (e) { - e.value = value - } - }) + const cookies = decodeURIComponent(document.cookie) + .split(';') + .map(cookie => cookie.trim().split('=')) + cookies.forEach(([id, value]) => { + if (!id || !value) { + return + } + const e = document.getElementById(id) + if (e) { + e.value = value + } + }) + {% endif %} } const clearErrors = () => {