Skip to content

Commit

Permalink
fix relogin
Browse files Browse the repository at this point in the history
  • Loading branch information
fancl committed Mar 25, 2024
1 parent dca4193 commit 3661c80
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,18 @@ func (c *Client) login(ctx context.Context, force bool) (err error) {
var (
buf []byte
tokenFile string
us *userSecurity
)
if tokenFile, err = os.UserHomeDir(); err != nil {
tokenFile = os.TempDir()
}
tokenFile = path.Join(tokenFile, ".miio.token")
if !force {
if buf, err = os.ReadFile(tokenFile); err == nil {
if err = json.Unmarshal(buf, &c.us); err == nil {
if buf, err = os.ReadFile(tokenFile); err == nil {
us = &userSecurity{}
if err = json.Unmarshal(buf, us); err == nil {
// less 5 minute
if !force || (force && time.Now().Unix()-us.Timestamp < 300) {
c.us = us
c.deviceID = c.us.DeviceID
c.prepareLogin()
return
Expand Down

0 comments on commit 3661c80

Please sign in to comment.