Skip to content

Fix stale logged-in UI when auth verify fails on network error - #833

Merged
devanshi14malhotra merged 1 commit into
devanshi14malhotra:mainfrom
nimra06:fix/auth-verify-network-failure
May 23, 2026
Merged

devanshi14malhotra merged 1 commit into
devanshi14malhotra:mainfrom
nimra06:fix/auth-verify-network-failure

Conversation

@nimra06

@nimra06 nimra06 commented May 20, 2026

Copy link
Copy Markdown
Contributor

Description

After a successful login, the app stores bibliodrift_user and isLoggedIn in local storage and runs verifyStoredAuthSession() on page load to validate the current session through GET /api/v1/auth/verify.

Previously, if the verification request failed because the backend was unreachable (backend stopped, offline mode, CORS issue, wrong origin, etc.), the app would still fall back to the cached storedUser from local storage. This caused the navbar to continue showing logged-in UI even though the session was never verified.

This PR updates verifyStoredAuthSession() in frontend/js/app.js so failed verification requests are treated the same as invalid sessions.

What changed

  • Clear stored auth data when session verification fails
  • Return null instead of using cached session state
  • Show signed-out navigation until verification succeeds again
  • Keep behavior consistent with existing 401 / 422 handling
  • Remove the duplicate credentials: 'include' entry from the same fetch call

Related Issue

Fixes #730

Type of Change

  • Bug Fix
  • Feature
  • Enhancement
  • Documentation

Testing

  1. Serve the frontend over HTTP
  2. Start the Flask backend
  3. Register or log in with a real account (not demo@bibliodrift.com)
  4. Confirm:
    • Logged-in navigation is visible
    • bibliodrift_user and isLoggedIn exist in local storage
  5. Stop the backend (or enable DevTools → Network → Offline)
  6. Reload index.html or library.html

Expected Result

  • Navbar shows signed-out navigation
  • Local auth keys are cleared
  • Console warns that session verification failed
  • Cached session state is no longer used
  1. Restart the backend and reload the page
  2. User should be required to sign in again

Screenshots

Optional: before/after navbar state when backend is unavailable.

Checklist

  • Code follows project guidelines
  • Tested locally
  • Documentation updated (not required)
  • PR title includes the appropriate contribution tag

Clear stored auth when /auth/verify cannot complete, matching 401/422 behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
@netlify

netlify Bot commented May 20, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for bibliodrift-dm ready!

Name Link
🔨 Latest commit 147964b
🔍 Latest deploy log https://app.netlify.com/projects/bibliodrift-dm/deploys/6a0dde6659d9a00008496a89
😎 Deploy Preview https://deploy-preview-833--bibliodrift-dm.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Wahid7852

Copy link
Copy Markdown

Looks good to me overall. Only thing worth noting is that temporary backend/network issues will now force logout instead of keeping cached auth state.

@devanshi14malhotra
devanshi14malhotra merged commit 9431cdf into devanshi14malhotra:main May 23, 2026
5 checks passed
@devanshi14malhotra devanshi14malhotra added level:beginner GSSoC'26 beginner level PR/issue gssoc:approved PR has been reviewed and is eligible for GSSoC points (for GSSoC'26) labels May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved PR has been reviewed and is eligible for GSSoC points (for GSSoC'26) level:beginner GSSoC'26 beginner level PR/issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: verifyStoredAuthSession keeps showing logged-in UI when /auth/verify fails due to network error

3 participants