Skip to content

Conversation

siverne
Copy link
Member

@siverne siverne commented Nov 16, 2026

Frontend part of #29. The backend was already done.

  • New page /konto: log in or create a user with the same form, and log out when you are logged in.
  • The menu shows your username, or «Logg inn».
  • AuthProvider keeps the logged-in user for the whole app. The session is an httpOnly cookie, so the frontend asks me to know who is logged in, and never touches the token.
  • Logging in updates the menu at once, and logging out clears everything that was fetched as the old user.
  • The backend only sends error codes, so the frontend translates them to Norwegian. Nothing the API writes is shown as it is.
  • The form uses the same rules as the backend (pattern, minLength) so the browser can say no before we ask, and autoComplete so password managers understand it.
  • RequireAuth is ready for pages that need a user, but nothing uses it yet: «Mine anmeldelser» still works without logging in.
  • Tests: logging in, wrong password, invalid username, logging out, the server being down, and axe.

Not in this PR: tying reviews and the wishlist to the account. That needs backend changes too, and is better as its own issue.

Note: the user migration has an older timestamp than the half-stars migration, so npm run db:migrate refuses to run it if you took half stars first. npx node-pg-migrate up --no-check-order once fixes it locally.

Tested: npm run check passes. Tried register, login, logout and reload in the browser.

@siverne siverne requested a review from a team as a code owner November 16, 2026 15:01
Copy link
Member

@williasc williasc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A failed logout looks like it worked, then quietly undoes itself (AuthProvider.tsx:502-511). The comment says “whatever the server said, this browser is logged out.” That isn’t true: the cookie is httpOnly, so only the server’s clearCookie ends the session.
If the logout request fails (offline, server error), finally sets me to null.
resetStore() then fetches me again. If that request gets through, the old cookie logs the user straight back in, with no message.
The error is also passed on to onClick={() => void logout()} in AccountPage.tsx:390, where nothing catches it.
Fix: return a message the way login and register do, only clear the store when the server confirms, and show the error under the button. One more test with an error mock on LOGOUT_MUTATION would cover it.

@williasc
Copy link
Member

Otherwise the PR looks great! If that's fixed it's ready to merge.
A few optional things:

  1. Login keeps the logged-out cache (AuthProvider.tsx:488). Logout resets the store but login only writes me. That’s harmless today because reviews aren’t tied to an account yet, but it matters once they are. Easy to forget, so it’s worth a note on the follow-up issue.
  2. Brief flash after login. Writing me re-renders the page as “Min konto” just before it moves to /mine. You’d barely see it, but navigating before writing the cache would avoid it.

@siverne
Copy link
Member Author

siverne commented Nov 16, 2026

Good catch on the logou @williasc , that was a real bug. Fixed: logout now returns a message the way login and register do, the store is only cleared when the server confirms, and the message shows under the button. New test with an error mock on LOGOUT_MUTATION covers it: the user stays logged in and is told what happened.

On the two optional ones: I am leaving both for the follow-up issue about tying reviews to the account, and I will note them there. Resetting the store on login only matters once reviews belong to a user, and the flash after login is a few milliseconds that would cost more in readability than it is worth right now.

@siverne siverne requested a review from williasc November 16, 2026 19:36
Copy link
Member

@williasc williasc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Pull request looks complete, and the login and logout functionality works great.

Ready to merge into main.

@williasc williasc merged commit 4fd31e3 into main Nov 16, 2026
@williasc williasc deleted the 29-login-frontend branch November 16, 2026 19:39
@manerlan manerlan mentioned this pull request Nov 16, 2026
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants