Example repository for debugging learning from this video
Here are two problems in this example code. Let's examine bug reports and fix them.
When I try to register user, it is registered. When I try to login to this user, I see "Unauthorized1" from ApplicationConfig:60.
- Run
docker compose up
to run a database - Run application
- Register user - POST request to
http://localhost:8080/api/v1/auth/register
with JSON body:
{
"name": "mark",
"username": "markov",
"password": "12345",
"passwordConfirmation": "12345"
}
- Login to this user - POST request
to
http://localhost:8080/api/v1/auth/login
with JSON body:
{
"username": "mark
"password": "12345"
}
- See "Unauthorized1"
Get JwtResponse
object with tokens.
Get Unauthorized1
Try to solve this problem during debugging process. I have some hints for you:
- Create
@RestControllerAdvice
class, handle exception and print stack trace - Find causes and code lines in stack trace
- Fix the first problem in UserRowMapper
- You need to add
if (resultSet.next()) {
just before lineuser.setId(resultSet.getLong("user_id"));
- Try to login again - you get new exception
- Fix the second problem in JwtTokenProvider. See actual code here
- Try to login again - all should work!
See this video for more details.