Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor StatefulAuthProvider for static initialization and improved session management #1861

Merged
merged 3 commits into from
Dec 17, 2024

Conversation

pastuxso
Copy link
Contributor

This refactor centralizes session management, reduces duplication, and improves maintainability across the extension.

  • Centralized session change notifications using a new SessionChangeHandler implemented with RxJS and a singleton pattern.
  • Refactored StatefulAuthProvider to follow a singleton pattern, simplifying its lifecycle and reducing dependencies.
  • Added functionality to retrieve sessions from secrets storage, avoiding potential infinite loops when checking sessions inside a session change listener.
  • Removed Kernel and RunmeUriHandler dependencies from StatefulAuthProvider for better modularity.
  • Introduced a new GraphQL client instantiator to encapsulate implementation details like authentication token configuration.
  • Ensured Webview refreshes correctly on login/logout events.

@pastuxso pastuxso marked this pull request as ready for review December 16, 2024 21:31
@@ -490,6 +490,14 @@ export class RunmeExtension {

if (kernel.isFeatureOn(FeatureName.RequireStatefulAuth)) {
await StatefulAuthProvider.instance.ensureSession()
StatefulAuthProvider.instance.currentSession().then(async (session) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pastuxso don't we need to await this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I realized we really needed to await this, as not doing so could lead to race conditions or unexpected behavior. To address this, I refactored the ensureSession function to properly return the session and updated the flow to await it where necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you have further suggestions!

Copy link
Member

@sourishkrout sourishkrout left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM

@sourishkrout sourishkrout merged commit b6a6acc into main Dec 17, 2024
1 check passed
@sourishkrout sourishkrout deleted the cris/refactor/auth-provider branch December 17, 2024 16:00
@sourishkrout
Copy link
Member

Let's break it in as a pre-release version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants