Skip to content

decouples the google auth from sheet service class and fixed side eff… - #82

Merged
Teja-Budumuru merged 1 commit into
mainfrom
google-sheet-operations
Aug 1, 2026
Merged

decouples the google auth from sheet service class and fixed side eff…#82
Teja-Budumuru merged 1 commit into
mainfrom
google-sheet-operations

Conversation

@Teja-Budumuru

@Teja-Budumuru Teja-Budumuru commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

…ects

Summary by CodeRabbit

  • New Features

    • Google OAuth credentials now refresh automatically when access tokens expire.
    • Refreshed credentials retain available email, scope, and refresh-token information.
    • Credential displays now show associated email addresses when available.
  • Bug Fixes

    • Clearing rows now correctly applies user-provided ranges to the selected sheet.
    • Improved handling of incomplete credential information during token refresh.

@Teja-Budumuru
Teja-Budumuru requested a review from Vamsi-o as a code owner August 1, 2026 14:05
Copilot AI review requested due to automatic review settings August 1, 2026 14:05
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 813baa2b-7b1d-4998-a85a-fc2b657297f6

📥 Commits

Reviewing files that changed from the base of the PR and between ba7d1f8 and ff11ad8.

📒 Files selected for processing (5)
  • apps/http-backend/src/services/token-refresh.service.ts
  • apps/web/app/workflows/[id]/components/ConfigModal.tsx
  • packages/nodes/src/common/google-oauth-service.ts
  • packages/nodes/src/google-sheets/google-sheets.executor.ts
  • packages/nodes/src/google-sheets/google-sheets.service.ts

📝 Walkthrough

Walkthrough

The change centralizes Google OAuth token refresh in GoogleOAuthService, persists refreshed credential metadata, updates backend refresh handling, adjusts credential email display, and qualifies custom Google Sheets clear ranges.

Changes

Google OAuth credential lifecycle

Layer / File(s) Summary
Centralized OAuth refresh lifecycle
packages/nodes/src/common/google-oauth-service.ts, packages/nodes/src/google-sheets/google-sheets.service.ts
GoogleOAuthService detects expiring tokens, refreshes credentials, preserves missing fields, and persists merged credentials. GoogleSheetsService no longer owns refresh logic.
Backend refresh integration
apps/http-backend/src/services/token-refresh.service.ts
The backend uses GoogleOAuthService directly and persists refreshed scope, email, and refresh-token values with fallbacks.
Credential email display
apps/web/app/workflows/[id]/components/ConfigModal.tsx
Credential badges read email from cred.config.email. A commented duplicate renderer was added.
Sheet range qualification
packages/nodes/src/google-sheets/google-sheets.executor.ts
Custom clear ranges now include the sheet name.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GoogleSheetsExecutor
  participant GoogleOAuthService
  participant GoogleOAuthProvider
  participant CredentialPersistence
  GoogleSheetsExecutor->>GoogleOAuthService: getCredentials
  GoogleOAuthService->>GoogleOAuthService: isTokenExpired
  GoogleOAuthService->>GoogleOAuthProvider: refreshAccessToken
  GoogleOAuthProvider-->>GoogleOAuthService: refreshed OAuth tokens
  GoogleOAuthService->>CredentialPersistence: persist merged credentials
  GoogleOAuthService-->>GoogleSheetsExecutor: return credentials
Loading

Possibly related PRs

Suggested reviewers: vamsi-o, copilot, tejabudumuru3

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch google-sheet-operations

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/http-backend/src/services/token-refresh.service.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

apps/web/app/workflows/[id]/components/ConfigModal.tsx

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

packages/nodes/src/common/google-oauth-service.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

  • 1 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Teja-Budumuru
Teja-Budumuru merged commit 52caf7c into main Aug 1, 2026
1 of 2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR moves Google OAuth token expiry/refresh logic out of GoogleSheetsService into the shared GoogleOAuthService, and updates consumers to rely on the centralized refresh behavior. It also tweaks Google Sheets “clear rows” range formatting and adjusts the web UI to read the credential email from the stored credential config.

Changes:

  • Removed token-expiry and token-refresh helpers from GoogleSheetsService and added them to GoogleOAuthService (including auto-refresh during getCredentials).
  • Updated Google Sheets executor logic to stop refreshing tokens itself and to build clear-range strings consistently.
  • Updated web UI credential display to use cred.config.email, and updated backend token refresh job to refresh via GoogleOAuthService.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/nodes/src/google-sheets/google-sheets.service.ts Removes embedded token expiry/refresh helpers from the Sheets service.
packages/nodes/src/google-sheets/google-sheets.executor.ts Stops per-execution token refresh and fixes clear-range construction.
packages/nodes/src/common/google-oauth-service.ts Centralizes token expiry check + refresh and performs auto-refresh in getCredentials.
apps/web/app/workflows/[id]/components/ConfigModal.tsx Adjusts credential email display to read from credential config.
apps/http-backend/src/services/token-refresh.service.ts Switches periodic refresh job to use GoogleOAuthService.refreshAccessToken and extends token shape.
Suppressed comments (1)

apps/http-backend/src/services/token-refresh.service.ts:41

  • refreshToken calls this.oauthService.refreshAccessToken(tokens.refresh_token) without validating that a refresh token exists. When refresh_token is missing/empty for an expiring credential, this will throw and mark the job as failed instead of returning a clear, actionable error.
    private async refreshToken(credentialId: string, tokens: OAuthTokens): Promise<RefreshResult> {
        try {

            // Use your existing refreshAccessToken method
            const newTokens = await this.oauthService.refreshAccessToken(tokens.refresh_token);

Comment on lines 8 to 11
expiry_date: number;
scope?: string;
email?: string
}
Comment on lines +109 to +113
async refreshAccessToken(refresh_token: string): Promise<OAuthTokens> {
try {
await this.oauth2Client.setCredentials({ refresh_token: refresh_token })
const { credentials } = await this.oauth2Client.refreshAccessToken();

Comment on lines 160 to 166
catch (error) {
throw new Error(`Failed to clear the rows: ${error}`)
}
}

isTokenExpired(): boolean {
const credentials = this.auth.credentials;
if (!credentials.expiry_date) return false;

return Date.now() >= credentials.expiry_date - (5 * 60 * 1000);
}

async refreshAccessToken(): Promise<GoogleSheetsCredentials> {
try {
const { credentials } = await this.auth.refreshAccessToken();

// IMPORTANT: Only include refresh_token if Google returns a new one
// Google doesn't always return a new refresh_token on every refresh
const result: GoogleSheetsCredentials = {
access_token: credentials.access_token || '',
refresh_token: '', // Will be set below if present
token_type: credentials.token_type || '',
expiry_date: credentials.expiry_date || 0
};

// Only include refresh_token if Google actually returned one
if (credentials.refresh_token) {
result.refresh_token = credentials.refresh_token;
}

return result;
}
catch (error) {
throw new Error(`Failed to refresh token: ${error}`)
}
}
}
Comment on lines 459 to 463
key={cred.id}
className="px-2.5 py-1 bg-emerald-500/15 text-emerald-400 text-xs rounded-full border border-emerald-500/20 font-medium"
>
{cred.email || cred.name}
{cred.config?.email || cred.name}
</span>
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.

3 participants