nailed it
This commit is contained in:
@@ -70,12 +70,29 @@ func (b *Bkosmi) Connect() error {
|
||||
|
||||
var token string
|
||||
if email != "" && password != "" {
|
||||
b.Log.Info("Authenticating with email/password...")
|
||||
token, err = loginWithChromedp(email, password, b.Log)
|
||||
// Try to load cached token first
|
||||
cachedToken, err := loadTokenCache(email, b.Log)
|
||||
if err != nil {
|
||||
return fmt.Errorf("authentication failed: %w", err)
|
||||
b.Log.Warnf("Failed to load token cache: %v", err)
|
||||
}
|
||||
|
||||
if cachedToken != nil {
|
||||
// Use cached token
|
||||
token = cachedToken.Token
|
||||
} else {
|
||||
// No valid cache, authenticate with browser
|
||||
b.Log.Info("Authenticating with email/password...")
|
||||
token, err = loginWithChromedp(email, password, b.Log)
|
||||
if err != nil {
|
||||
return fmt.Errorf("authentication failed: %w", err)
|
||||
}
|
||||
b.Log.Info("✅ Authentication successful")
|
||||
|
||||
// Save token to cache
|
||||
if err := saveTokenCache(token, email, b.Log); err != nil {
|
||||
b.Log.Warnf("Failed to cache token: %v", err)
|
||||
}
|
||||
}
|
||||
b.Log.Info("✅ Authentication successful")
|
||||
} else {
|
||||
b.Log.Info("No credentials provided, using anonymous access")
|
||||
// token will be empty, client will get anonymous token
|
||||
|
||||
Reference in New Issue
Block a user