fix: refactor credential handling in user routes and update credentia…#63
fix: refactor credential handling in user routes and update credentia…#63
Conversation
…l logic in useCredentials hook
📝 WalkthroughWalkthroughBackend and frontend modifications to credential handling: backend now fetches credentials via GoogleSheetsNodeExecutor instead of direct database queries and manages CredentialsID separately in node operations; frontend updated to handle both credential arrays and authUrl strings in API responses. Changes
Sequence DiagramsequenceDiagram
participant Frontend as Frontend<br/>(useCredential Hook)
participant Backend as Backend<br/>(userRoutes)
participant Executor as GoogleSheetsNodeExecutor
participant DB as Credentials DB
Frontend->>Backend: GET /getCredentials
Backend->>Executor: new GoogleSheetsNodeExecutor()
Executor->>DB: getAllCredentials(userId, type)
DB-->>Executor: credentials array (or empty)
Executor-->>Backend: credentials or []
alt Credentials Found
Backend-->>Frontend: {credentials, hasCredentials: true}
Frontend->>Frontend: Update cred state
else No Credentials
Backend-->>Frontend: "No credentials found"
Frontend->>Frontend: Set authUrl = response
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/http-backend/src/routes/userRoutes/userRoutes.ts (1)
188-198: Type check is incorrect—string auth URLs will be returned as credentials.Based on
GoogleSheetsNodeExecutor.getAllCredentials(fromgoogle-sheets.executor.ts), when no credentials are found, it returnsthis.oauthService.getAuthUrl(userId)which is a string. Since strings have a.lengthproperty (character count),credentials.length === 0will befalsefor a non-empty auth URL, causing the auth URL to be returned withhasCredentials: true.🐛 Proposed fix
- if (credentials.length === 0) { + if (typeof credentials === 'string') { + // Backend returned auth URL when no credentials exist + return res.status(200).json({ + message: "No credentials found", + authUrl: credentials, + hasCredentials: false, + }); + } + + if (!Array.isArray(credentials) || credentials.length === 0) { return res.status(200).json({ message: "No credentials found", }); }
🧹 Nitpick comments (2)
apps/web/app/hooks/useCredential.ts (1)
31-37: Consider removing commented-out code.If the OAuth URL construction is now handled by the backend response, this commented block should be removed rather than left as dead code. Keeping commented code reduces readability.
🧹 Suggested cleanup
- // Frontend defines where to redirect for OAuth - // if (type === "google") { - // const baseUrl = `${BACKEND_URL}/oauth/google/initiate`; - // const url = workflowId ? `${baseUrl}?workflowId=${workflowId}` : baseUrl; - // setAuthUrl(url); - // } else { - // setAuthUrl(null); - // }apps/http-backend/src/routes/userRoutes/userRoutes.ts (1)
165-187: Remove commented-out code blocks.These commented blocks represent the old implementation. Git history preserves this code if needed later. Leaving large commented blocks reduces readability.
…l logic in useCredentials hook
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.