Skip to content

[Bug]: OnboardingRoute guard condition incorrectly redirects users whose Firestore document hasn't loaded yet #547

Description

@Rishikapurbey

Bug Description

In AppRoutes.jsx, the OnboardingRoute guard contains this condition to redirect away from onboarding:
if (userData?.onboardingStatus === "complete" || !isOnboarding || (userData && userData.onboardingStatus !== "incomplete"))

The third clause (userData && userData.onboardingStatus !== "incomplete") is triggered whenever userData exists and onboardingStatus is anything other than "incomplete" — including undefined. Since Firestore userData loads asynchronously after authentication, there is a brief window where userData is populated (the document exists) but onboardingStatus hasn't been written yet (e.g. a race condition during first-time account creation in Onboarding.jsx's runTransaction). During this window, userData.onboardingStatus is undefined, which is !== "incomplete", so the third clause fires and redirects the user away from /onboarding before they can complete it.

Root Cause:
The third condition is redundant with the first (onboardingStatus === "complete") but additionally catches the undefined case, which is a legitimate intermediate state during first-time onboarding. The loading check above only guards against auth loading, not Firestore document loading.

Steps to Reproduce:

  1. Create a new GitHub account and log in for the first time.
  2. During the brief window between user document creation and onboardingStatus being set to "incomplete", the route guard evaluates userData.onboardingStatus as undefined.
  3. The third clause fires and redirects the user to /dashboard before onboarding completes.

Expected Behavior:
OnboardingRoute should only redirect away from /onboarding when onboardingStatus is explicitly "complete", not when it is undefined or any other intermediate value. Users with an incomplete or pending onboarding document should always be allowed to stay on /onboarding.

Affected File(s):

  • src/routes/AppRoutes.jsx (OnboardingRoute component)

Suggested Fix:
Simplify the redirect condition to only check the two explicit cases: userData?.onboardingStatus === "complete" || (userData && !isOnboarding), removing the third redundant clause that incorrectly matches undefined onboardingStatus values.

Metadata

Metadata

Assignees

Labels

NSoC'26NSoC 2026backendBackend/Firebase related changesbugSomething isn't workingdocumentationImprovements or additions to documentationenhancementNew feature or requestfrontendFrontend related changes (HTML/CSS/JS/React)gssocGirlScript Summer of Codegssoc26GirlScript Summer of Code 2026needs-reviewIssue needs reviewneeds-triagensocNSoC

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions