Repository navigation
Description
Problem
src/app/auth/callback/CallbackClient.tsx was updated to close #77 ("CallbackClient always redirects to /dashboard/contributor after GitHub OAuth; AuthUser.roles is fetched but never read anywhere") by adding role-aware redirect logic:
useEffect(() => {
const token = searchParams.get("token");
if (!token) { setError(...); return; }
window.history.replaceState({}, "", window.location.pathname);
login(token)
.then(() => {
router.replace(redirectForRoles(user?.roles));
})
.catch(() => setError("Could not complete sign-in. Please try again."));
}, [searchParams, login, router, user]);user comes from useAuth() (AuthContext), and AuthContext.login() is persistToken(token); await refresh(); — it resolves Promise<void>, it does not return the freshly-fetched user. The .then(() => router.replace(redirectForRoles(user?.roles))) callback is a closure over whatever user was at the time this particular effect invocation was created — which, for someone landing on /auth/callback to complete their first sign-in, is null (they aren't authenticated yet). login()'s own internal refresh() call is what eventually calls setUser(profile) with the real, role-bearing profile — but that state update happens after this closure was already created and captured user = null.
So on the effect's first pass, redirectForRoles(user?.roles) evaluates with roles as undefined, which redirectForRoles explicitly falls back to ROLE_REDIRECT_MAP.contributor for — the exact "always contributor" behavior #77 was filed to fix, just now hidden behind a role-precedence map that looks correct but never actually receives the resolved roles on the pass that matters.
Compounding this: user is listed in this effect's own dependency array, so once login()'s refresh() call does update user, the effect re-runs. On that second run, searchParams.get("token") is read again — useSearchParams() does not reactively reflect the raw window.history.replaceState() call from the first run (that API doesn't trigger Next.js's router-state update), so token is likely still truthy, meaning login(token) can fire a second time with the same token, triggering another redundant /auth/me + /users/:id round-trip and a second router.replace(...) call.
Impact
Every first-time OAuth sign-in is at real risk of landing on /dashboard/contributor regardless of the user's actual role(s) — the specific bug #77 is titled after — because the redirect decision is made from a stale, pre-login user value. On top of that, the same effect's dependency on user creates a realistic path to a redundant second login() call and a second navigation, which at best wastes two network round-trips and at worst produces a visible flash to the wrong dashboard followed by a second redirect (or, if searchParams behaves differently than expected on the re-run, an "No token was returned" error flashing immediately after a successful sign-in).
Suggested fix
Have AuthContext.login() return the resolved AuthUser (or resolve refresh()'s result) so CallbackClient can redirect based on the value login() actually just fetched, rather than reading a separate, independently-updating user from context:
// AuthContext.tsx
const login = useCallback(async (token: string): Promise<AuthUser | null> => {
persistToken(token);
return refresh(); // have refresh() return the resolved user (or null)
}, [refresh]);// CallbackClient.tsx
login(token)
.then((resolvedUser) => {
router.replace(redirectForRoles(resolvedUser?.roles));
})
.catch(...);and drop user from this effect's dependency array (it's no longer needed once the redirect reads login()'s own resolved value), which also removes the redundant-second-run risk.
Activity
shadrach68 commentedon Sep 17, 2026
Hi Maintainer,
I'd like to take on this issue. I've reviewed the requirements, understand the scope, and can deliver a tested solution that aligns with the project's standards.
Thanks.
ranjeet150 commentedon Sep 17, 2026
Hello @maintainers,
I can tackle
CallbackClient's redirectForRoles(user?.roles) reads a stale pre-login closure value, likely still always redirecting new sign-ins to /dashboard/contributor (#77 regression). Proposed implementation roadmap:MergeFi/frontendCallbackClient's redirectForRoles(user?.roles) reads a stale pre-login closure value, likely still always redirecting new sign-ins to /dashboard/contributor (#77 regression)with proper loading/error states and clean component architecture.Happy to pick this up today—please assign to me!
Eeboade commentedon Sep 24, 2026
@Eeboade has applied to work on this issue as part of the Stellar Wave Program's 9th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Eeboade to this issue.
innocentharuna commentedon Sep 24, 2026
@innocentharuna has applied to work on this issue as part of the Stellar Wave Program's 9th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @innocentharuna to this issue.
VeronicDev commentedon Sep 24, 2026
@VeronicDev has applied to work on this issue as part of the Stellar Wave Program's 9th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @VeronicDev to this issue.
Confidence001Jewel-cmd commentedon Sep 24, 2026
@Confidence001Jewel-cmd has applied to work on this issue as part of the Stellar Wave Program's 9th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Confidence001Jewel-cmd to this issue.
stpatrickghost commentedon Sep 24, 2026
@stpatrickghost has applied to work on this issue as part of the Stellar Wave Program's 9th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @stpatrickghost to this issue.
Noragiftfr commentedon Sep 24, 2026
@Noragiftfr has applied to work on this issue as part of the Stellar Wave Program's 9th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Noragiftfr to this issue.
drips-wave commentedon Sep 24, 2026
Congratulations, @Noragiftfr! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on September 30, 2026.
🧑💻 @Noragiftfr: 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 🌊
fix: accessibility improvements and stale closure bug (#413, #414, #415)
Merge pull request #538 from Noragiftfr/fix/a11y-and-callback-stale-user
drips-wave commentedon Sep 26, 2026
This issue has been completed by @Noragiftfr as part of the Stellar Wave Program's 9th Wave 🥳
😎 @Noragiftfr: 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.