Skip to content

Commit

Permalink
refactor: change auth controller to /auth route
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuspegorari committed Jan 13, 2024
1 parent 81a4f67 commit 7595770
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/teamoff/api/controller/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
@RequestMapping("/auth")
public class AuthController {

private final AuthenticationManager manager;
Expand All @@ -26,12 +26,14 @@ public AuthController(AuthenticationManager manager, TokenService tokenService)
this.tokenService = tokenService;
}

@PostMapping

@PostMapping("/login")
public ResponseEntity<Object> login(@RequestBody @Valid AuthRequestDTO data){
Authentication authentication = manager.authenticate(
new UsernamePasswordAuthenticationToken(data.login(), data.password())
);
var tokenJWT = tokenService.generateToken((Auth) authentication.getPrincipal());
return ResponseEntity.ok(new TokenResponseDTO(tokenJWT));
}

}

0 comments on commit 7595770

Please sign in to comment.