Skip to content

fix: use user token for friends leaderboard - #898

Closed
GhanshyamJha05 wants to merge 2 commits into
Coder-s-OG-s:mainfrom
GhanshyamJha05:codex/fix-issue-889-friends-leaderboard
Closed

fix: use user token for friends leaderboard#898
GhanshyamJha05 wants to merge 2 commits into
Coder-s-OG-s:mainfrom
GhanshyamJha05:codex/fix-issue-889-friends-leaderboard

Conversation

@GhanshyamJha05

@GhanshyamJha05 GhanshyamJha05 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #889.

The Friends leaderboard failed for users who did not have a personal GitHub App installation. This includes users who signed in through an organization-level installation, where github_installations.user_id is null.

Root cause

When no user-specific installation was found, getFollowedHandles fell back to getAppOctokit(). That client authenticates with a GitHub App JWT, which cannot call GET /users/{username}/following. The request returned 401, the error was swallowed, and the leaderboard silently displayed only the current user.

Changes

  • Read the signed-in GitHub OAuth provider token from the Supabase session.
  • Use getUserOctokit(providerToken) when no personal installation exists.
  • Keep installation-token authentication for users with a personal installation.
  • Avoid making an invalid App-JWT request when no user token is available.
  • Add regression coverage for organization-install users.

Validation

  • Typecheck: passed
  • Lint: passed
  • Format check: passed
  • Focused Vitest run: blocked by the local Windows sandbox with an esbuild access-denied error while loading vitest.config.ts; no test assertion failure occurred.

Co-authored-by: GhanshyamJha05 <168712839+GhanshyamJha05@users.noreply.github.com>
@GhanshyamJha05

Copy link
Copy Markdown
Contributor Author

@Ayush4958 review

@Ayush4958 Ayush4958 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fix Relying on session.provider_token is a short term patch. Supabase does not persist the OAuth token indefinitely; it disappears when the session refreshes.

When that happens, the friends leaderboard will silently break again for org install users until they log out and back in.

Long term, this feature requires a UI error prompting the user to install the app on their personal account.

}
}

let userAccessToken: string | null = null;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Performance Regression Fetching sb.auth.getSession() at the top of getLeaderboard forces a network/database round trip on every single request before the cache is checked. This entirely defeats the caching mechanism for high traffic public leaderboards which adds massive latency.

Fix: Move userAccessToken retrieval into the cache miss branch, exclusively for when scope === 'friends'

@Ayush4958

Copy link
Copy Markdown
Collaborator

Long term, this feature requires a UI error prompting the user to install the app on their personal account.

@jakharmonika364 @Ayush-Patel-56
Take a look at this

@Ayush4958

Copy link
Copy Markdown
Collaborator

Hi @GhanshyamJha05 sry for this but
Instead of hacking around the missing installation with a transient token, we should address the actual problem. If a user doesn't have a personal installation, the UI should explicitly block the Friends Leaderboard and show a clear call-to-action: "You need a personal GitHub App installation to view the Friends Leaderboard. [Click here to install].

@Ayush4958

Ayush4958 commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

I will suggest you to open a new PR with the fix
I mentioned, I will be closing this one

@Ayush4958 Ayush4958 closed this Aug 18, 2026
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.

[BUG] Friends leaderboard falls back to the GitHub App JWT for users without a personal install

2 participants