Skip to content
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

"Keep me logged in" does not save token to localstorage #10676

Closed
3 tasks done
diogotcorreia opened this issue Nov 21, 2021 · 10 comments
Closed
3 tasks done

"Keep me logged in" does not save token to localstorage #10676

diogotcorreia opened this issue Nov 21, 2021 · 10 comments
Labels
Bug Current Bug in UI - Extra Attention

Comments

@diogotcorreia
Copy link

Checklist

  • I have updated to the latest available Home Assistant version.
  • I have cleared the cache of my browser.
  • I have tried a different browser to see if it is related to my browser.

Describe the issue you are experiencing

It seems like the new "Keep me logged in" button does not store the token to local storage as one would expect. It is kept in memory and lost when the tab is closed.

Describe the behavior you expected

Ticking the "Keep me logged in" checkbox should actually leave you logged in and store the token to local storage.

Steps to reproduce the issue

  1. Spin up a clean Home Assistant instance using devcontainers
  2. Create a new account (e.g. test with password test123)
  3. Log out
  4. On the login page, tick the "Keep me logged in" checkbox
  5. Enter the credentials to login
  6. Click the "LOGIN" button
  7. Close the tab and open Home Assistant on a new one
  8. You're not logged in

What version of Home Assistant Core has the issue?

core-2021.11.5

What was the last working version of Home Assistant Core?

core-2021.10.*

In which browser are you experiencing the issue with?

Brave 1.32.106 (Chromium 96.0.4664.45) - Also tested on Firefox 94.0.2

Which operating system are you using to run this browser?

ArchLinux (Kernel 5.15.3-arch1-1)

State of relevant entities

No response

Problem-relevant frontend configuration

No response

Javascript errors shown in your browser console/inspector

No response

Additional information

Probably introduced by #10226

@diogotcorreia diogotcorreia added the Bug Current Bug in UI - Extra Attention label Nov 21, 2021
@diogotcorreia
Copy link
Author

So after playing around with this, I noticed that this only happens on the first time you load up the page (perhaps because the JavaScript chunks are still loading?). If you refresh after you've logged in, then it goes back to the login page but the token is now stored correctly.

Note that clicking the logout button on the profile page "starts over", that is, it doesn't fix the issue. However, deleting the entry from local storage and refreshing correctly works.

I'm still investigating more about this issue.

@ntoff
Copy link

ntoff commented Nov 24, 2021

I have just started having this issue. After it working as I would expect for a little over a week, suddenly I find myself being logged out while interacting with the UI. Logging in, and hitting refresh will bring me back to the login page.

Sometimes I would be trying to add an automation (click the add automation button), something would flash on the screen (I assume the wizard, it goes away too fast to see what it was) and I'd end up just being logged out. So it definitely wasn't due to inactivity.

Creating a new user and logging in with that user instead, seems to have fixed the issue, but I don't know for how long.

I'm using home-assistant (latest tag) in docker on a synology nas following the official instructions, and for about a week it worked perfectly, then there was an update pushed to the docker registry, updated, and that's when the issues started. I tried going back to the old image (which I had saved to local storage) but even that previously working image was now broken too. Tried using the "stable" tag and still the same result, so I don't think the update was necessarily the cause.

Happens in firefox and chrome, the only "solution" so far for me was to create a new user with a different login name. I tried removing all stored passwords, clearing cookies, clearing cache, logging out of the mobile app (in case that was somehow conflicting).

I'm not entirely sure whether my issue is the same, but it seems very similar.

@diogotcorreia
Copy link
Author

@ntoff A workaround that I've found is to login, then refresh and login again. To check if you're correctly logged in, look if you have the hassTokens on your localStorage (through the dev tools of your browser; in Chromium, click F12, then Application).

Alternatively, you can execute this on the JavaScript console to save the tokens in memory to localStorage while logged in:

localStorage.setItem("hassTokens", JSON.stringify(window.__tokenCache.tokens))

@spacegaier
Copy link
Member

I can also confirm the same issue. I was able to reproduce it, but my initial analysis did not turn up what is going wrong.

I think that when I had set some breakpoints, it worked with the first login directly, but when I wanted to confirm that again alter I wasn't able to...so not completely sure. But that might point to a timing issue potentially.

@ntoff
Copy link

ntoff commented Nov 25, 2021

@ntoff A workaround that I've found is to login, then refresh and login again. To check if you're correctly logged in, look if you have the hassTokens on your localStorage (through the dev tools of your browser; in Chromium, click F12, then Application).

Alternatively, you can execute this on the JavaScript console to save the tokens in memory to localStorage while logged in:

localStorage.setItem("hassTokens", JSON.stringify(window.__tokenCache.tokens))

Confirm this does seem to keep me logged in, and that my login isn't otherwise being saved to local storage without manually saving it. Weird that only one username (for me the user affected is "admin") is affected though?

If there's anything else you need me to try, let me know. I have HA running through docker currently, but could just as easily set it up manually or throw it on a spare raspberry pi.

@pickeld
Copy link

pickeld commented Dec 3, 2021

hey. any update? same issue here

@Tyfosho
Copy link

Tyfosho commented Dec 6, 2021

Same issue here. Tried on multiple browsers and devices.

@Akszyn
Copy link

Akszyn commented Dec 10, 2021

I have the same problem as other users that from version 2021.11.x that it doesn't remember my login details in the Android app. The problem occurred when I reinstalled the ha application, so i don't have how to use the development tools or f12 on my phone with Android 11

@bramkragten
Copy link
Member

this is fixed in the current beta

@emile-bodin
Copy link

I see this is closed, can you tell us in which version this is fixed?

I am experiencing similar issues, but running higher version
core: core-2021.12.3
Supervisor: core-2021.12.2

@github-actions github-actions bot locked and limited conversation to collaborators Jan 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Current Bug in UI - Extra Attention
Projects
None yet
Development

No branches or pull requests

8 participants