fix(integrations): Google Search Console and Google Analytics still show "Connected" after the token expires - #252
Open
eryawww wants to merge 1 commit into
Open
Conversation
getGscConnection/getGa4Connection reported "connected" based only on whether a connection row existed, never re-checking the underlying Google grant. A revoked/expired token showed as permanently "Connected" with no way to reconnect from Settings > Integrations, even though the same failure was already correctly detected (and surfaced a working reconnect flow) by the dashboard's own report cards and by the seo-geo-cron jobs calling the same connection through OpenSEO's MCP. Adds GscService.verifyConnection / Ga4Service.verifyConnection, which make the same one-call live probe (listSites / listProperties) the existing per-account grant-status checks already use, scoped to the specific stored connection. Wires both into the connection-status server functions so Settings > Integrations now shows the real state and lets the user reconnect directly, matching what klaussa.com's own project is hitting right now (GSC api_error, GA4 ga4_reconnect_required).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expected
Settings > Integrationsshould tell you when a Google connection actually stops working, not just whether you connected it once.Current state
getGscConnectionandgetGa4Connectiononly check whether a connection row exists in the database. Once GSC or GA4 is connected, the badge reads "Connected" forever, even after Google revokes or expires the token. Nothing on that page tells you it's broken, and there's no way to reconnect from there.The rest of the codebase already handles this correctly.
GscCardandGa4Cardon the dashboard call a real report endpoint and fall back to a connect prompt when the grant is dead.listSitesForUserWithGrantStatusandlistPropertiesForUserWithGrantStatusdo the same live check per account.Settings > Integrationsis the one place that never actually asks Google.I hit this on a project I run: GSC returned api_error and GA4 returned ga4_reconnect_required through the MCP tools, while Integrations still showed both connections green.
Solution
Added
GscService.verifyConnectionandGa4Service.verifyConnection. Each makes one live call,listSitesorlistProperties, against the connection's stored account. It is the same call the grant-status checks already use elsewhere. If Google rejects it, the function returns false.Wired both into
getGscConnectionandgetGa4Connectionso the page shows the real state.Prioritizing minimal change. 10 new tests cover the working and broken paths. Typecheck is clean.