Skip to content

Refactor: Improve auth flow and service initialization#11

Merged
allenhutchison merged 5 commits intomainfrom
adh/auth-refactor
Nov 14, 2025
Merged

Refactor: Improve auth flow and service initialization#11
allenhutchison merged 5 commits intomainfrom
adh/auth-refactor

Conversation

@allenhutchison
Copy link
Contributor

Refactor: Improve auth flow and service initialization

This commit refactors the authentication and service initialization logic to be more robust and on-demand.

Key changes:

  • On-demand clients: Service clients (Docs, Sheets, etc.) are now created on-demand for each request, rather than being initialized once at startup. This ensures that each request has a valid and authenticated client.
  • Token auto-refresh: The AuthManager now automatically refreshes expired tokens.
  • auth.clear tool: A new auth.clear tool has been added to allow users to manually clear their authentication credentials.
  • Removed initialize(): The initialize() method has been removed from all services, simplifying the service lifecycle.

These changes improve the reliability of the extension by preventing authentication errors and making the code easier to maintain.

This commit refactors the authentication and service initialization logic to be more robust and on-demand.

Key changes:

*   **On-demand clients:** Service clients (Docs, Sheets, etc.) are now created on-demand for each request, rather than being initialized once at startup. This ensures that each request has a valid and authenticated client.
*   **Token auto-refresh:** The `AuthManager` now automatically refreshes expired tokens.
*   **`auth.clear` tool:** A new `auth.clear` tool has been added to allow users to manually clear their authentication credentials.
*   **Removed `initialize()`:** The `initialize()` method has been removed from all services, simplifying the service lifecycle.

These changes improve the reliability of the extension by preventing authentication errors and making the code easier to maintain.
@allenhutchison
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a great refactoring effort that significantly improves the authentication flow and service initialization. Moving to on-demand client creation makes the services more robust against token expiration, and the automatic token refresh in AuthManager is a key enhancement. The addition of the auth.clear tool is also a thoughtful feature for error recovery. The changes are well-implemented across all services and their corresponding tests. I've found a critical issue that could lead to a server crash and a couple of other points for improvement, but overall this is a solid and valuable change.

@allenhutchison
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a significant and well-executed refactor of the authentication and service initialization logic. Moving to on-demand client creation for each request and removing the initialize() methods greatly improves the robustness and simplifies the service lifecycle. The addition of automatic token refreshing in AuthManager, along with the new auth.clear and auth.refreshToken tools, provides a much more resilient authentication flow. The new tests for AuthManager are thorough and cover critical edge cases. I have a couple of suggestions to improve code clarity and maintainability.

@allenhutchison allenhutchison merged commit 0c25705 into main Nov 14, 2025
6 checks passed
@allenhutchison allenhutchison deleted the adh/auth-refactor branch November 19, 2025 19:26
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