try and persist session tokens

This commit is contained in:
Evan Jarrett
2025-11-07 22:43:44 -06:00
parent 4d5182e2b2
commit 4667d34b46
+18
View File
@@ -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{