From 517d7edbc89dc27c6af4b619bc4c96ee962e0426 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Thu, 10 Sep 2020 15:28:24 +0200 Subject: [PATCH] Make login work when sessionStorage is not available. Thanks to Ralf Treinen for pointing out the issue. --- static/sfu.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/static/sfu.js b/static/sfu.js index c5cb5bf..16eb454 100644 --- a/static/sfu.js +++ b/static/sfu.js @@ -11,18 +11,31 @@ let group; /** @type {ServerConnection} */ let serverConnection; +/* Some browsers disable session storage when cookies are disabled, + we fall back to a global variable. */ +let fallbackUserPass = null; + function setUserPass(username, password) { - window.sessionStorage.setItem( - 'userpass', - JSON.stringify({username: username, password: password}), - ); + let userpass = {username: username, password: password}; + try { + window.sessionStorage.setItem('userpass', JSON.stringify(userpass)); + fallbackUserPass = null; + } catch(e) { + console.warn("Couldn't store password:", e); + fallbackUserPass = {username: username, password: password}; + } } function getUserPass() { - let userpass = window.sessionStorage.getItem('userpass'); - if(!userpass) - return null; - return JSON.parse(userpass); + let userpass; + try { + let json = window.sessionStorage.getItem('userpass'); + userpass = JSON.parse(json); + } catch(e) { + console.warn("Couldn't retrieve password:", e); + userpass = fallbackUserPass; + } + return userpass || null; } function getUsername() {