Skip to content

Commit bb992b6

Browse files
committed
Fix for token expiration #12
1 parent fac5b21 commit bb992b6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

internal/accounts.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package internal
22

33
import (
44
"errors"
5+
"time"
56

67
"github.com/AlexxIT/SmartScaleConnect/pkg/core"
78
"github.com/AlexxIT/SmartScaleConnect/pkg/garmin"
@@ -21,9 +22,16 @@ const (
2122
AccZeppXiaomi = "zepp/xiaomi"
2223
)
2324

24-
var accounts = map[string]core.Account{}
25+
var accounts map[string]core.Account
26+
var cacheTS time.Time
2527

2628
func GetAccount(fields []string) (core.Account, error) {
29+
// Clean accounts every 23 hours, because there is no logic for token expiration.
30+
if now := time.Now(); now.After(cacheTS) {
31+
accounts = map[string]core.Account{}
32+
cacheTS = now.Add(23 * time.Hour)
33+
}
34+
2735
key := fields[0] + ":" + fields[1]
2836
if account, ok := accounts[key]; ok {
2937
return account, nil

0 commit comments

Comments
 (0)