0

I want to login with multiple logins for the domain in same browser. example there is a messaging service call slack if i login in first tab and if i open second tab in same browser it should no share session with second tab it should be altogether a new one.

I've tried below block of code but it is not working how do i acheive this

var clearLocal = window.localStorage.clear.bind(window.localStorage);
var getLocal = window.localStorage.getItem.bind(window.localStorage);
var keyLocal = window.localStorage.key.bind(window.localStorage);
var removeLocal = window.localStorage.removeItem.bind(window.localStorage);
var setLocal = window.localStorage.setItem.bind(window.localStorage);
window.localStorage.getItem = function(key) {
  alert("inside account  key " + key);

  var newKey = accountId + "::" + key;
  alert("inside account new key " + newKey);

  return getLocal(newKey);
}

window.localStorage.key = function(index) {
  console.log("KEY " + index);
  return keyLocal(index);
}

window.localStorage.removeItem = function(key) {
  var newKey = accountId + "::" + key;
  console.log("REMOVE " + newKey);
  return removeLocal(newKey);
}

window.localStorage.setItem = function(key, value) {
  var newKey = accountId + "::" + key;
  alert("inside account new key " + newKey);

  return setLocal(newKey, value);
}

Any suggestions more appreciated..

adiga
  • 34,372
  • 9
  • 61
  • 83
zack
  • 137
  • 12
  • I wouldn't hold login details in local storage - it can easily be read and so isn't very secure to do so. Also most sites won't allow multiple logins at the same time - usually you would have to use different browsers if you want to login with multiple users – Pete May 10 '19 at 13:25
  • but [this](https://chrome.google.com/webstore/detail/sessionbox-free-multi-log/megbklhjamjbcafknkgmokldgolkdfig?hl=en) guy is doing that in same browser multiple logins . – zack May 10 '19 at 13:26
  • That looks more like a browser plugin than a website thing - but if you want to use front end tech, then use sessionStorage as I think that is per tab - but as I say I wouldn't use a site that held credentials like that and it probably won't help with sites that use server side sessions as they are still shared between tabs https://stackoverflow.com/questions/5523140/html5-local-storage-vs-session-storage – Pete May 10 '19 at 13:31
  • Slack uses subdomains, on each subdomain cookies can be different, and local storage is different – Dimitar Nestorov May 10 '19 at 15:01

0 Answers0