log in and sign up linked together

I tried to implement a login and signup system where both forms are linked together, allowing users to switch between them easily. I also set up a mock API to simulate backend interactions, but I’m facing several challenges:

  1. Form Switching: I’m having trouble toggling between the login and signup forms smoothly. The UI doesn’t update as expected, and sometimes it loses the user’s input or causes unexpected behavior.
  2. Mock API Handling: I set up a mock API to handle login and signup requests, but I’m not sure if I’m simulating the API responses correctly. I’m facing issues with returning success or error responses, and I’m unsure how to handle these responses properly on the frontend.
  3. Authentication State: Managing the user’s authentication state is proving difficult. I need to ensure that once a user successfully logs in or signs up, they are redirected appropriately, but my current implementation doesn’t handle this well.
  4. Validation and Error Handling: Implementing form validation for both login and signup forms has been challenging. I also need to show relevant error messages when something goes wrong, like invalid input or failed login attempts, but my current error handling is either incomplete or not working as expected.

I’m looking for detailed examples or guidance on how to address these issues effectively.