nailed it

This commit is contained in:
cottongin
2025-11-02 16:48:18 -05:00
parent f764519a30
commit 9262ae79dd
3 changed files with 28 additions and 4 deletions

View File

@@ -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