New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Web: Fix local storage clearing #27256
Conversation
cd63976
to
ca1f33d
Compare
Shouldn't we also update last active on login as an extra measure to prevent this? Can you also link to the PR that introduced the issue? |
i did think about it, but didn't think it was really necessary to reset the here are the cases where we auto log the user out (which should clear local storage):
if you still think it's a nice to have, i'll add it |
const keys = []; | ||
for (let i = 0; i < window.localStorage.length; i++) { | ||
const key = window.localStorage.key(i); | ||
|
||
keys.push(window.localStorage.key(i)); | ||
} | ||
keys.forEach(key => { | ||
if (!KEEP_LOCALSTORAGE_KEYS_ON_LOGOUT.includes(key)) { | ||
window.localStorage.removeItem(key); | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker, but we can clean this up a bit by just using Object.keys
Object.keys(window.localStorage).forEach
4a5c60c
to
53b316c
Compare
fixes #27254
fixes a bug where upon logout, the local storage was not getting cleared as expected.
i'm not sure if i am explaining this right, but the previous code, as we were deleting keys, the next index value did not necessarily meant it was the
next key
. if the previous key was deleted, then the next index value may refer to next next key (or out of bounds). so depending on the order of keys, it was a delete or miss, which is why users were havinginconsistent
issues with login/logoutsthe incident was: when a user logged in, the user got logged right back out, and it was because the local storage key
LAST_ACTIVE: 'grv_teleport_last_active'
was not getting deleted, so it kept the old expired value.this bug was introduced (backported) starting from
12.4.0
when i wrote the test, i tested it against the old code first, which failed
i was also able to replicate the issue where my local storage wasn't getting cleared
re @zac about
teleport/web/packages/teleport/src/components/Authenticated/Authenticated.tsx
Line 76 in dbcb8a8