aidenhuynh / Epic_CSA

MIT License
0 stars 0 forks source link

Login Debugging on teacher_portfolio #5

Open aidenhuynh opened 6 months ago

aidenhuynh commented 6 months ago

How to Run with Debugger

Frontend

  1. Run locally using bundler, use whatever port bundle exec jekyll serve -P 4001

  2. Open up post/markdown page locally Screen Shot 2024-03-05 at 9 18 41 AM

  3. Open inspect and navigate to js code Screen Shot 2024-03-05 at 9 19 59 AM

  4. Add breakpoints by clicking on the line numbers on the left. Screen Shot 2024-03-05 at 9 19 45 AM

  5. When running code, press the arrow to step through each breakpoint. In our case, the code will be run when attempting to login. Screen Shot 2024-03-05 at 10 13 50 AM

Backend

  1. Navigate to Main.java
  2. In VSCode, press on the arrow next to the run button and click "Debug Java" Screen Shot 2024-03-05 at 9 43 22 AM

Demonstration

First, we run our frontend locally with bundle exec jekyll serve -P 4001 and navigate to http://localhost:4001/teacher_portfolio/java/login (You can choose any port, but preferably not 4000 to see a CORS error later)

Then, inspect element and find the "login" js code in Sources

Setting three breakpoints on the .fetch, .then, and .catch allows us to see possible points of error from our frontend. Screen Shot 2024-03-05 at 9 19 45 AM

The following errors occur in different cases when trying to sign in:

  1. ERR_CONNECTION_REFUSED occurs from not running the backend, and is fixed by doing so Screen Shot 2024-03-05 at 9 23 41 AM

  2. This CORS error occurs from not allowing the correct origins on MvcConfig.java Screen Shot 2024-03-05 at 9 24 04 AM

This error is fixed by making sure the origin is allowed, and in this case, we had to change the port to match our localhost.

@Override
    public void addCorsMappings(@NonNull CorsRegistry registry) {
        registry.addMapping("/**").allowedOrigins("https://nighthawkcoders.github.io", "http://localhost:4001"); // Changed port to 4001 from 4000
    }
  1. The 401 error occurs from an authorization issue, which in this case was from incorrect login credentials Screen Shot 2024-03-05 at 9 26 41 AM

This is fixed by making sure to use the correct login information from Person.java, as we testing with a random password, instead of the actual password initialized within the file.

Successful Run

The expected outcome of properly avoiding all of these errors is being redirected to the data page (http://localhost:4001/teacher_portfolio/java/data). Yay!

Screen Shot 2024-03-05 at 9 27 48 AM