fix: use user token for friends leaderboard - #898
Conversation
Co-authored-by: GhanshyamJha05 <168712839+GhanshyamJha05@users.noreply.github.com>
|
@Ayush4958 review |
Ayush4958
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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'
@jakharmonika364 @Ayush-Patel-56 |
|
Hi @GhanshyamJha05 sry for this but |
|
I will suggest you to open a new PR with the fix |
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_idis null.Root cause
When no user-specific installation was found,
getFollowedHandlesfell back togetAppOctokit(). That client authenticates with a GitHub App JWT, which cannot callGET /users/{username}/following. The request returned 401, the error was swallowed, and the leaderboard silently displayed only the current user.Changes
getUserOctokit(providerToken)when no personal installation exists.Validation
vitest.config.ts; no test assertion failure occurred.