Our three-person capstone team is planning an app with React, Node and Express, and PostgreSQL. We have three user roles, and hosted authentication services are off limits. Where should we start with designing and building auth?
How should we build auth without a hosted service?
Answers
Start with a conventional server-side session rather than building a separate authentication service. On registration, hash passwords with a maintained Argon2 or bcrypt library and store the hash, never the password. On login, verify the password and create a random session identifier stored on the server. Send the identifier in a cookie with HttpOnly, Secure, and an appropriate SameSite setting.
Plan session expiration, logout, and invalidation as part of the design. Use HTTPS, add CSRF protection for cookie-authenticated requests, and rate-limit login attempts. A JWT is another option, but it isn't required just because React is involved.
Reply to this answer
Keep authentication and authorization separate. Authentication tells your server who the user is. Authorization decides what that user can do.
For the three roles, sketch a table of allowed actions before writing routes. Put shared role checks in Express middleware, but also check ownership where it matters. A role alone may not answer whether someone can edit a particular record. React can hide controls for convenience, but the API needs to enforce every permission.
Reply to this answer
Read through an established authentication framework's documentation and implementation, even if you can't use it directly. It'll give you a better checklist than just looking at a login form: registration, session handling, password resets, email verification, and failure cases all need decisions.
Check the capstone rules on libraries too. Banning a hosted service doesn't necessarily mean you have to write password hashing or other security primitives yourself.
Reply to this answer
Keep the scope manageable. A central auth service for multiple applications can be useful, but for one capstone app it adds another system to design and maintain. A well-defined auth module inside the Express app is a reasonable starting point.
Use the planning phase to map the flows and decide how you'll test them, including expired sessions, wrong passwords, and attempts to access another role's routes.
Reply to this answer
Add your answer
Answers are reviewed before publication.
k!9~plaidrivet:
Also rotate the session identifier after login so an existing anonymous session can't simply become an authenticated one.