Skip to content

Auth state doesn't persist across navbar pages #24

Description

@plyfofun

When a user authenticates via GitHub in the navbar, the login succeeds and their username/email is displayed correctly — but only on the page where they logged in. Navigating to any other page in the navbar (Challenges, Worksheets, Projects, Learn, etc.) shows the navbar reverted to the logged-out state ("Authenticate via GitHub"), even though the underlying Firebase session is still active.

Expected behavior

The navbar should reflect the logged-in state consistently across every page — showing the username and Logout button as long as the Firebase session is active.

Actual behavior

Only the page where login happened shows the authenticated state. Every other page renders the default logged-out navbar.

Root cause

The auth UI is split across two scripts that aren't loaded together:

  • js/components/navbar.js injects the navbar — including the login/logout buttons and the #user-telemetry element — and is included on all pages.
  • js/base/auth-logic.js is what actually wires up the buttons and runs Firebase's onAuthStateChanged listener to update the UI. It is currently included on only one pageindex.html.

Firebase persists the session across page loads by default, so the user is still logged in on the other pages. The problem is purely that no script runs onAuthStateChanged there to apply the state to the navbar, so the buttons never update.

Additional note

The script tag in index.html points to src="auth-logic.js" (repo root), but the file now lives at js/base/auth-logic.js after commit e04d148 ("moved auth-logic to the correct folder"). This path is likely broken and should be fixed as part of this work.

Possible fix

Load the auth module on every page rather than just index.html. The cleanest approach is to have js/components/navbar.js itself import/inject auth-logic.js (so auth is guaranteed wherever the navbar renders), or add the corrected <script type="module"> tag with the right relative path to each page. Note that pages under pages/ need the ../ prefix, which navbar.js already computes for its other assets.

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions