Skip to content

CallbackClient always redirects to /dashboard/contributor after GitHub OAuth; AuthUser.roles is fetched but never read anywhere #77

Closed

Description

@chonilius

Overview

After a successful GitHub OAuth round-trip, CallbackClient sends every single user to the same place, unconditionally:

useEffect(() => {
  const token = searchParams.get("token");
  if (!token) {
    setError("No token was returned by GitHub sign-in.");
    return;
  }
  login(token)
    .then(() => router.replace("/dashboard/contributor"))
    .catch(() => setError("Could not complete sign-in. Please try again."));
}, [searchParams, login, router]);

login(token) calls AuthContext.login → refresh(), which fetches the full profile via /auth/me then /users/${session.userId} — resolving to an AuthUser that already carries roles: UserRole[] ("contributor" | "maintainer" | "sponsor", src/types/index.ts:1,82-89). That field is fetched from the backend on every single auth resolution, and then never read: I grepped the entire src/ tree for .roles and got zero matches outside the type declaration itself. Nothing in this frontend — not CallbackClient, not Navbar, not DashboardShell — ever branches on user.roles.

The concrete, visible consequence here: a maintainer or sponsor who signs in with GitHub for the very first time is redirected to /dashboard/contributor regardless of what roles the backend just told this app they have. If they only have roles: ["sponsor"] (say, an organization's funding lead who has never contributed code and never will), they land on a page built entirely around personal claims/earnings/PR stats that don't apply to them at all, and have to manually discover the "Dashboards" nav dropdown to find the page that actually matches who they are.

This is a real, verifiable, main-branch-current gap distinct from #48 ("Fix Navbar loading-state flashes and multi-role rendering logic"), which is scoped to Navbar.tsx's own loading/rendering behavior — this issue is about the OAuth post-login redirect target in an entirely different file (CallbackClient.tsx), and about the broader fact that the roles field the backend already sends is completely inert throughout the app, not about any specific navbar rendering bug.

Requirements

  • Change CallbackClient's post-login redirect to consider user.roles (available after login(token) resolves, via useAuth()'s user) rather than hardcoding /dashboard/contributor. Define a sane precedence when a user has multiple roles (e.g. prefer maintainer > sponsor > contributor, or whichever ordering the product actually wants — this is a real decision, not a mechanical one, and should be stated explicitly in the PR).
  • Handle the case of a user with an empty roles array (a brand-new GitHub sign-in with no role assigned yet, if that's a state the backend can produce) — falling back to /dashboard/contributor as a sane default for that specific case is reasonable, but should be an explicit, intentional branch, not the unconditional behavior for every user.
  • This issue is intentionally scoped to CallbackClient.tsx's redirect decision. Do not also rewrite Navbar.tsx's or DashboardShell.tsx's role-based rendering as part of this fix — that territory is already covered by Fix Navbar loading-state flashes and multi-role rendering logic #48; note in the PR that user.roles is currently unused anywhere in the app (this issue's own grep finding) so whoever picks up Fix Navbar loading-state flashes and multi-role rendering logic #48 has that context, but keep this PR's diff scoped to the redirect target alone.

Acceptance Criteria

  • A user whose roles includes "maintainer" (and not "contributor") is redirected to /dashboard/maintainer after completing GitHub OAuth, not /dashboard/contributor.
  • A user whose roles includes "sponsor" (and not "contributor" or "maintainer") is redirected to /dashboard/sponsor.
  • A user with multiple roles is redirected per an explicit, documented precedence order.
  • A user with an empty/absent roles array still lands somewhere sensible (no broken redirect, no infinite loop, no crash) — document which fallback was chosen and why.
  • A test covers each of the above redirect-target cases by mocking useAuth()'s login/user and asserting router.replace is called with the expected path.

Additional Notes

Precise references:

  • src/app/auth/callback/CallbackClient.tsx:13-23 — the full effect, router.replace("/dashboard/contributor") hardcoded at line 21 regardless of the resolved user.
  • src/types/index.ts:1 (export type UserRole = "contributor" | "maintainer" | "sponsor";) and :82-89 (AuthUser.roles: UserRole[]).
  • src/context/AuthContext.tsx:56-62 — login(token): persistToken(token); await refresh(); — confirms user is populated (via refresh()'s setUser(profile)) by the time login()'s returned promise resolves, so CallbackClient can read the resolved role list immediately after await login(token) without an extra round-trip.
  • Grep evidence: grep -rn "\.roles" src/ (run against main @ 9c8f4b3) returns zero matches anywhere in application code — confirming roles is fetched by every single auth resolution and never consulted by anything today, which is the underlying condition that makes this specific redirect bug possible and worth flagging explicitly rather than assuming it's a one-off oversight.

Edge cases: router.replace runs inside a .then() after login(token) — if login resolves but the subsequent /users/${session.userId} fetch inside refresh() itself fails (caught internally by AuthContext.refresh's own try/catch, which calls clearToken(); setUser(null) on failure — see AuthContext.tsx:35-46), then user would be null at the moment CallbackClient tries to read user.roles for the redirect decision, even though login(token)'s promise itself resolved successfully (refresh() doesn't rethrow on its own internal catch). Handle this explicitly — don't assume user is non-null just because login() didn't throw.

Test/reproduction plan: render CallbackClient with a token search param present, mock useAuth() to return a login that resolves and a user with roles: ["maintainer"], and assert router.replace is called with /dashboard/maintainer. Repeat for ["sponsor"], ["maintainer", "sponsor"] (precedence check), and []/undefined (fallback check).

Activity

  1. added
    bug
    very hard
    architecture
    Maybe Rewarded
    GrantFox OSS
    Official Campaign | FWC26
    on Aug 16, 2026
  2. added
    Third Campaign
    on Aug 16, 2026
  3. added
    Stellar Wave
    on Aug 25, 2026
  4. Muzzy-Cyber commented on Aug 25, 2026

    @Muzzy-Cyber

    @Muzzy-Cyber has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hello, I have carefully gone through this issue and I would definitely like to work on it. Thank you.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Muzzy-Cyber to this issue.

  5. Songu3020 commented on Aug 25, 2026

    @Songu3020

    @Songu3020 has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hi! I’m a full-stack developer with a strong blockchain background. I’d love to handle this issue and can deliver a clean, reliable solution. Kindly assign it to me.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Songu3020 to this issue.

  6. ridwanraji1290-ai commented on Aug 25, 2026

    @ridwanraji1290-ai

    @ridwanraji1290-ai has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hello, this issue looks like a good match for my skills. I’d be glad to take it on and ensure the final implementation meets the stated requirements.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @ridwanraji1290-ai to this issue.

  7. Ukorstack commented on Aug 25, 2026

    @Ukorstack

    @Ukorstack has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    I would love to work on this issue. Please assign it to me.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Ukorstack to this issue.

  8. brightcli-stack commented on Aug 25, 2026

    @brightcli-stack
    Contributor

    @brightcli-stack has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    hello can i work on this issue please

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @brightcli-stack to this issue.

  9. p4uld4vid016-code commented on Aug 25, 2026

    @p4uld4vid016-code

    @p4uld4vid016-code has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hello maintainer, i would like to work on this issue

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @p4uld4vid016-code to this issue.

  10. Leemxiey commented on Aug 25, 2026

    @Leemxiey

    @Leemxiey has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hello maintainer, I would love to work on this issue

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Leemxiey to this issue.

  11. Muyideen-js commented on Aug 25, 2026

    @Muyideen-js

    @Muyideen-js has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    I'd like to implement role-based redirects in CallbackClient by reading user.roles from the auth context after login resolves, with explicit precedence (e.g., maintainer > sponsor > contributor) and a fallback to /dashboard/contributor for empty roles arrays. I'd add tests covering maintainer, sponsor, multi-role, and empty-roles scenarios to verify each redirect target.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Muyideen-js to this issue.

  12. Promzy204-bad commented on Aug 25, 2026

    @Promzy204-bad

    @Promzy204-bad has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    I would like to work on this issue

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Promzy204-bad to this issue.

  13. drips-wave commented on Aug 25, 2026

    @drips-wave

    Congratulations, @brightcli-stack! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on August 31, 2026.

    🧑‍💻 @brightcli-stack: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

    Warning

    When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

    🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

    🌊 Happy Wave 🌊

  14. added a commit that references this issue on Aug 25, 2026
    b6cb677
  15. drips-wave commented on Aug 25, 2026

    @drips-wave

    This issue has been completed by @brightcli-stack as part of the Stellar Wave Program's 8th Wave 🥳

    😎 @brightcli-stack: You earned 200 Points for completing this issue! After the current Wave ends, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.

    🧑‍💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.

  16. removed
    Stellar Wave
    on Oct 15, 2026
  17. added
    Stellar Wave
    on Oct 15, 2026
  18. removed
    Stellar Wave
    on Oct 15, 2026
  19. added
    Stellar Wave
    on Oct 15, 2026
  20. removed
    Stellar Wave
    on Oct 15, 2026
  21. added
    Stellar Wave
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

GrantFox OSSMaybe RewardedOfficial Campaign | FWC26Stellar WaveThird Campaignarchitecturebugvery hard

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions