diconium / ethereal-pulse

Apache License 2.0
0 stars 3 forks source link

Develop authentication and authorisation mechanisms for WebAPP #20

Open almeiphi opened 3 weeks ago

almeiphi commented 3 weeks ago

Implement JWT-based authentication and authorisation mechanisms using Remix full-stack capabilities. This will allow users to securely log in and access protected resources through a dedicated middleware.

Requirements

  1. User Registration

    • Create route with correct validations.
    • Hash passwords before storing them in the database.
    • Generate a JWT upon successful registration.
  2. User Login

    • Create route with correct validations.
    • Validate user credentials and generate a JWT upon successful authentication.
  3. JWT Generation

    • Generate a JWT with a payload containing the user ID and other relevant information.
    • Sign the JWT with a secret key.
    • Set an expiration time for the JWT.
  4. JWT Verification

    • Implement middleware utilities to verify the JWT on protected routes.
    • Decode the JWT and attach user information to the request object.
  5. Protected Routes

    • Protect routes in the BFF that require authentication using the JWT verification middleware.
    • Ensure only authenticated users can access these routes.
  6. Logout

    • Invalidate the JWT on the client side (e.g., by removing it from local storage).

Steps to Implement

  1. User Registration Endpoint

    • [ ] Create a registration endpoint (/register).
    • [ ] Hash the user’s password using bcrypt.
    • [ ] Store the user information in simulated database.
  2. User Login Endpoint

    • [ ] Create a login endpoint (/login).
    • [ ] Validate the user credentials.
    • [ ] Generate a JWT and return it to the client upon successful login.
  3. JWT Utility Functions

    • [ ] Create utility functions in the BFF to generate and verify JWTs.
    • [ ] Use the jsonwebtoken library to handle JWT operations.
  4. JWT Middleware

    • [ ] Implement middleware to verify JWTs on protected routes.
    • [ ] Decode the JWT and attach user information to the request object.
  5. Protecting Routes

    • [ ] Apply the JWT middleware to routes that require authentication.
    • [ ] Ensure unauthorised requests receive an appropriate response.
  6. Integration with Remix WebAPP

    • [ ] Ensure the Remix web application uses the JWT for authenticating users.
    • [ ] Update the web application to store the JWT in a secure cookie upon successful login.
  7. Logout Functionality

    • [ ] Implement client-side logout functionality in the web application.
    • [ ] Ensure the JWT is removed from cookie upon logout.
  8. Documentation and Testing

    • [ ] Document relevant methods.
    • [ ] Write tests for the registration, login, and JWT verification processes.

Resources

Acceptance Criteria

Additional Information


teixeped commented 2 days ago

Edited ticket to reflect Astro to Remix change