You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(worker): refresh OAuth tokens in backend permission sync flow (#1000)
* fix(worker): refresh OAuth tokens in backend permission sync flow
Token refresh was previously only triggered from the Next.js jwt callback,
meaning tokens could expire between user visits and cause account-driven
permission sync jobs to fail silently.
Move refresh logic to packages/backend/src/ee/tokenRefresh.ts and call it
from accountPermissionSyncer before using an account's access token. On
refresh failure, tokenRefreshErrorMessage is set on the Account record and
surfaced in the linked accounts UI so users know to re-authenticate.
Also adds a DB migration for the tokenRefreshErrorMessage field and wires
the signIn event to clear it on successful re-authentication.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* changelog
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
### Fixed
14
14
-[EE] Fixed account-driven permission sync silently wiping all Bitbucket Server repository permissions when the OAuth token expires on instances with anonymous access enabled. [#998](https://github.com/sourcebot-dev/sourcebot/pull/998)
15
15
-[EE] Fixed Bitbucket Server repos being incorrectly treated as public in Sourcebot when the instance-level `feature.public.access` flag is disabled but per-repo public flags were not reset. [#999](https://github.com/sourcebot-dev/sourcebot/pull/999)
16
+
-[EE] Fixed account-driven permission sync jobs failing when OAuth tokens expire between user visits by moving token refresh into the backend sync flow. [#1000](https://github.com/sourcebot-dev/sourcebot/pull/1000)
// Get a list of all repos that the user has access to from all connected accounts.
189
191
constrepoIds=await(async()=>{
190
192
constaggregatedRepoIds: Set<number>=newSet();
191
193
192
194
if(account.provider==='github'){
193
-
if(!accessToken){
194
-
thrownewError(`User '${account.user.email}' does not have an GitHub OAuth access token associated with their GitHub account. Please re-authenticate with GitHub to refresh the token.`);
195
-
}
196
-
197
195
// @hack: we don't have a way of identifying specific identity providers in the config file.
198
196
// Instead, we'll use the first connection of type 'github' and hope for the best.
thrownewError(`User '${account.user.email}' does not have a GitLab OAuth access token associated with their GitLab account. Please re-authenticate with GitLab to refresh the token.`);
249
-
}
250
-
251
245
// @hack: we don't have a way of identifying specific identity providers in the config file.
252
246
// Instead, we'll use the first connection of type 'gitlab' and hope for the best.
thrownewError(`User '${account.user.email}' does not have a Bitbucket Cloud OAuth access token associated with their account. Please re-authenticate with Bitbucket Cloud to refresh the token.`);
289
-
}
290
-
291
281
// @note: we don't pass a user here since we want to use a bearer token
292
282
// for authentication.
293
283
constclient=createBitbucketCloudClient(/* user = */undefined,accessToken)
@@ -305,10 +295,6 @@ export class AccountPermissionSyncer {
thrownewError(`User '${account.user.email}' does not have a Bitbucket Server OAuth access token associated with their account. Please re-authenticate with Bitbucket Server to refresh the token.`);
310
-
}
311
-
312
298
// @hack: we don't have a way of identifying specific identity providers in the config file.
313
299
// Instead, we'll use the first Bitbucket Server connection's URL as the base URL.
0 commit comments