Skip to content

Conversation

hasanmo
Copy link
Member

@hasanmo hasanmo commented Oct 8, 2026

Change

Added functional registration, login, and logout through GraphQL, with users and sessions stored in PostgreSQL.

Authentication returns a real user object and updates shared Zustand state and the site header. Session tokens are stored in localStorage and validated through the API to restore login after refresh or reopening the page.

Added Drizzle migrations, updated generated GraphQL types, and added authentication and session tests.

Closes [#32](#32)

Database and local setup

Requires a running PostgreSQL instance. The local database is t31_project2, with authentication tables under the project2 schema.

Create the database if it does not already exist:

psql -h 127.0.0.1 -U postgres -d postgres -W -c "CREATE DATABASE t31_project2;"

Configure DATABASE_URL in the environment file loaded by the API:

DATABASE_URL=postgresql://YOUR_DB_USER:YOUR_URL_ENCODED_PASSWORD@127.0.0.1:5432/t31_project2

Keep local credentials and environment files out of Git.

From the repository root, check migration consistency and apply migrations:

cd apps/api
npx drizzle-kit check --config drizzle.config.ts
npx tsx src/db/migrate.ts
cd ../..

The Drizzle check validates migration consistency. The migration command applies the migrations to the configured database.

Verify that the tables were created:

psql -h 127.0.0.1 -U postgres -d t31_project2 -W -c "\dt project2.*"

After registering a user, verify persistence without displaying password hashes:

psql -h 127.0.0.1 -U postgres -d t31_project2 -W -c "SELECT id, name, email FROM project2.users;"

The API must be running for registration, login, session restoration, and logout to work.

Verification

Manually verified:

  • Registration and user persistence in PostgreSQL
  • Login and logout locally
  • Session restoration after reopening the page

Validation commands from the repository root:

npm run typecheck
npm run lint
npm run test
npm run build

Course requirements and AI use

Supports end-to-end frontend/backend integration, GraphQL, database persistence, user state management, and testing.

AI was used as a development aid for implementation, tests, and troubleshooting. I reviewed and refined the generated suggestions and code.

@hasanmo hasanmo requested a review from a team as a code owner October 8, 2026 12:43
@hasanmo hasanmo changed the base branch from main to dev October 8, 2026 12:47
Copy link
Member

@oliveror oliveror left a comment

Choose a reason for hiding this comment

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

My review was assistend by AI. The overall approach looks reasonable, but I would not approve this for production yet.

Required changes

  1. Handle API errors in the login and registration pages. Failed requests currently reject without showing the user an error message.

  2. Do not remove the stored session token when session restoration fails because of a temporary network or API error. Only remove it when the API confirms that the session is invalid or expired.

  3. Add tests covering:

    • Invalid login credentials
    • Registration with an existing email
    • API/network errors during login and registration
    • Network errors during session restoration

Recommended follow-up

  • Make user creation and session creation atomic to avoid orphaned users.
  • Replace the remaining “mock authentication” text now that authentication is backed by PostgreSQL.
  • Document the security trade-off of storing session tokens in localStorage.

The current tests pass after installing dependencies, but they do not cover the failure paths above.

@hasanmo
Copy link
Member Author

hasanmo commented Oct 11, 2026

My review was assistend by AI. The overall approach looks reasonable, but I would not approve this for production yet.

Required changes

  1. Handle API errors in the login and registration pages. Failed requests currently reject without showing the user an error message.

  2. Do not remove the stored session token when session restoration fails because of a temporary network or API error. Only remove it when the API confirms that the session is invalid or expired.

  3. Add tests covering:

    • Invalid login credentials
    • Registration with an existing email
    • API/network errors during login and registration
    • Network errors during session restoration

Recommended follow-up

  • Make user creation and session creation atomic to avoid orphaned users.
  • Replace the remaining “mock authentication” text now that authentication is backed by PostgreSQL.
  • Document the security trade-off of storing session tokens in localStorage.

The current tests pass after installing dependencies, but they do not cover the failure paths above.

Viser feilmelding når innlogging eller registrering feiler.
Hindrer at skjemaet sendes inn flere ganger samtidig.
Beholder innloggingstokenet ved nettverksfeil.
Oppretter bruker og sesjon samlet, slik at feil ikke etterlater en halvferdig konto.
Fjernet mock-tekst og dokumentert sikkerheten.
Lagt til flere tester. Alle 133 tester består.

@hasanmo hasanmo requested a review from oliveror October 11, 2026 07:33
Copy link
Member

@olestan olestan left a comment

Choose a reason for hiding this comment

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

Looks very good overall, just one or two small things. The first would be really nice to fix before merging; the second is more of a nice-to-have.

First: it would be good to add authenticated routes in the React router. Right now /cookbook and /recipes/new are still accessible while logged out. Could we add a RequireAuth/ProtectedRoute wrapper? We should also wait for session restoration before redirecting, otherwise a valid logged-in user could get sent to /login on refresh.

Second: it might be nice to send the session token through the Authorization header and resolve the user in the GraphQL context. This is less of a merge blocker, but it would make future authenticated queries/mutations cleaner since we wouldn’t need to pass sessionToken explicitly everywhere.

@hasanmo
Copy link
Member Author

hasanmo commented Oct 11, 2026

Looks very good overall, just one or two small things. The first would be really nice to fix before merging; the second is more of a nice-to-have.

First: it would be good to add authenticated routes in the React router. Right now /cookbook and /recipes/new are still accessible while logged out. Could we add a RequireAuth/ProtectedRoute wrapper? We should also wait for session restoration before redirecting, otherwise a valid logged-in user could get sent to /login on refresh.

Second: it might be nice to send the session token through the Authorization header and resolve the user in the GraphQL context. This is less of a merge blocker, but it would make future authenticated queries/mutations cleaner since we wouldn’t need to pass sessionToken explicitly everywhere.

Good points, the first one is added but the second one can be handled when we implement the CRUD part.

@hasanmo hasanmo merged commit bde18ec into dev Oct 11, 2026
2 checks passed
hasanmo added a commit that referenced this pull request Oct 13, 2026
…foundation (#49)

* 2 set up global styles and design tokens (#3)

* feat: add design tokens and cascade layers

* feat: add global reset and base styles

* feat: add shared style utilities and wire global styles

* test: add visual style verification pages

* docs: document styling structure and usage

* fix: apply Prettier formatting for CI

* 5 add shared icon library (#6)

* feat: add shared icon library

* feat: add reusable Icon component

* test: add icon showcase for visual verification

* fix: apply Prettier formatting to icon files

* Add foundational UI components (#8)

feat: add foundational UI components

- add shared UI utility components
- add UI component test setup
- add test cleanup after each test
- added visual showcases, for design and responsive testing
- handle avatar initials safely
- apply Prettier formatting to UI components

* Add form navigation UI components (#10)

Add form navigation UI components
* feat: add form UI components

* feat: add selection and filter components

* feat: add navigation and menu components

* test: add form and navigation component verification

* fix: apply Prettier formatting to UI components

* 9 build the app shell and core routes (#11)

* feat(shell): add app shell and core routes

Refs: #9

* feat(shell): refine app shell structure and navigation

Refs: #9

* fix(shell): tune responsiveness of site-header

Refs: #9

* fix(web): add mobile viewport metadata

Refs: #9

* fix(shell): reduce space between header and content

Refs: #9

* Add feedback overlay UI components (#13)

* feat: add feedback UI components

* feat: add dialog and overlay components

* test: add feedback and overlay component verification

* docs: document shared UI component library

* fix: apply Prettier formatting to UI components

* feature(recipes): add recipe models and mock dataset (#15)

Co-authored-by: Hasan Mohammad Fawzi <hasan.fawzi@hoglund.no>

* feature(auth): implement D1-05 mock authentication flow (#17)

* feature(auth): add mock authentication flow

* fix(auth): align mock user with shared data strategy

---------

Co-authored-by: Hasan Mohammad Fawzi <hasan.fawzi@hoglund.no>

* Add reusable RecipeCard and recipe metadata components (#18)

* feat: add reusable logo mark

* feat: add shared recipe metadata components

* feat: add reusable RecipeCard

* feat: add RecipeCard showcase

* test: add RecipeCard interaction tests

* fix: apply Prettier formatting to RecipeCard files

* comment(docs): add project concept and setup guide (#19)

* comment(docs): add project concept and setup guide

* comment(docs): Update readme doc

---------

Co-authored-by: Hasan Mohammad Fawzi <hasan.fawzi@hoglund.no>

* style: fix Prettier formatting

* style: fix Prettier formatting

* test: align quality checks with auth pages

* fix(deploy): retry API health check during startup (#22)

Co-authored-by: Hasan Mohammad Fawzi <hasan.fawzi@hoglund.no>

* Add Explore-page with pagination and search (#26)

* feat: add reusable pagination helper and tests

* feat: implement Explore search and recipe browsing

* docs: clarify AI use in development

* fix: improve Explore focus and status feedback

* fix: Applied prettier to ExplorePage

* Explore filters, URL state, and Save to Cookbook (#31)

* feat(explore): add responsive filter and sort controls

* feat(explore): implement browse query and URL state

* feat(explore): add shared mock save state

* docs(explore): add server integration notes

* 35 frontend for add recipe (#40)

* feat: add initial RecipeCreatePage

Refs: #35

* chore(add recipe): update recipe routing in App

Refs: #35

* feat(add recipe): add image preview

Refs: #35

* chore(add recipe): resize instruction box

Refs: #35

* feat(add recipe): add custom styling to image selector

Refs: #35

* feat(add recipe): add drag-and-drop for images and update styling

Refs: #35

* feat(add recipe): add re-order of ingredients and instructions

Refs: #35

* Implement My Cookbook Frontend with Mock Data (#43)

* feat: implement cookbook browsing with shared recipe logic

* fix: refine cookbook filters and navigation semantics

* fix: make sheet body scroll within viewport

* test(cookbook): cover apply, clear and invalid mobile filters

* refactor(header): use LogoMark and LinkButton (#45)

* D1-14: Implement Recipe Detail (#46)

* feat(recipe-detail): implement recipe detail page

* feat(recipe-detail): improve accessibility, add test recipe, and update tests

* feat(recipe-detail): refine serving amount rounding

* style(recipe-detail): refine layout and responsive sizing

* test(recipe-detail): update tests for responsive controls

* test(e2e): update recipe detail smoke test to use a real recipe route

* Hasan/feat/database auth (#41)

* feat(auth): add database authentication and persistent sessions

* fix(auth): address review feedback

* fix(auth): protect routes and await session restoration

* fix(routes): use cookbook and recipe detail pages

* fix(routes): render recipe detail page after merge

* fix(e2e): align smoke tests with recipe and protected routes

---------

Co-authored-by: Hasan Mohammad Fawzi <hasan.fawzi@hoglund.no>

* Added 404-handling and Not Found Page

* Hasan/feat/database model (#47)

* feat(auth): add database authentication and persistent sessions

* fix(auth): address review feedback

* feat(db): add recipe database model and migration

* fix(db): address recipe model review feedback

---------

Co-authored-by: Hasan Mohammad Fawzi <hasan.fawzi@hoglund.no>

---------

Co-authored-by: Ole Stangeland <olestan@stud.ntnu.no>
Co-authored-by: Oliver Ørjavik <oliveror@stud.ntnu.no>
Co-authored-by: Hasan Mohammad Fawzi <hasan.fawzi@hoglund.no>
@olestan olestan deleted the hasan/feat/database-auth branch October 15, 2026 10:13
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants