diff --git a/pkg/auth/oauth/refresher.go b/pkg/auth/oauth/refresher.go index 80e9840..f744bc4 100644 --- a/pkg/auth/oauth/refresher.go +++ b/pkg/auth/oauth/refresher.go @@ -134,6 +134,24 @@ func (r *Refresher) resumeSession(ctx context.Context, did string) (*oauth.Clien return nil, fmt.Errorf("failed to resume session: %w", err) } + // Set up callback to persist token updates to SQLite + // This ensures that when indigo automatically refreshes tokens, + // the new tokens are saved to the database immediately + session.PersistSessionCallback = func(callbackCtx context.Context, updatedData *oauth.ClientSessionData) { + if err := r.app.GetClientApp().Store.SaveSession(callbackCtx, *updatedData); err != nil { + slog.Error("Failed to persist OAuth session update", + "component", "oauth/refresher", + "did", did, + "sessionID", sessionID, + "error", err) + } else { + slog.Debug("Persisted OAuth token refresh to database", + "component", "oauth/refresher", + "did", did, + "sessionID", sessionID) + } + } + // Cache the session r.mu.Lock() r.sessions[did] = &SessionCache{