Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
@@ -9,18 +9,15 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import hackathon.FrisbYEE.jpa.metier.Athlete;
|
||||
import hackathon.FrisbYEE.jpa.service.AthleteDAO;
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/users")
|
||||
@CrossOrigin(origins = "http://localhost:3000")
|
||||
public class UserSyncResource {
|
||||
|
||||
@Autowired
|
||||
private AthleteDAO athleteDAO;
|
||||
|
||||
@@ -28,13 +25,10 @@ public class UserSyncResource {
|
||||
@Transactional
|
||||
public ResponseEntity<Void> sync() {
|
||||
Jwt jwt = (Jwt) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
|
||||
String keycloakId = jwt.getSubject();
|
||||
String firstName = jwt.getClaimAsString("given_name");
|
||||
String lastName = jwt.getClaimAsString("family_name");
|
||||
|
||||
if (!athleteDAO.existsByKeycloakId(keycloakId)) {
|
||||
System.out.println("New user detected from Keycloak. Syncing: " + firstName + " " + lastName);
|
||||
Athlete athlete = new Athlete();
|
||||
athlete.setKeycloakId(keycloakId);
|
||||
athlete.setName(lastName);
|
||||
@@ -42,7 +36,6 @@ public class UserSyncResource {
|
||||
athlete.setRole(hackathon.FrisbYEE.jpa.metier.Role.athlete);
|
||||
athleteDAO.save(athlete);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user