fix auth
This commit is contained in:
parent
379a398bc1
commit
5b64559933
@ -7,6 +7,7 @@ import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -37,7 +38,18 @@ public class AuthenticationController {
|
||||
if (token == null)
|
||||
return ResponseEntity.internalServerError().build();
|
||||
|
||||
return ResponseEntity.ok(new AuthenticationResponse(user.getUsername(), user.getDisplayName(), token));
|
||||
return ResponseEntity.ok(new AuthenticationResponse(user, token));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<StratsUser> getLoggedInUser() {
|
||||
return ResponseEntity.ok(getUser());
|
||||
}
|
||||
|
||||
private StratsUser getUser() {
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
StratsUser user = (StratsUser) auth.getPrincipal();
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package me.akito123321.valoStrats.rest.requests;
|
||||
|
||||
public record AuthenticationResponse(String username, String displayName, String token) {
|
||||
import me.akito123321.valoStrats.schemas.StratsUser;
|
||||
|
||||
public record AuthenticationResponse(StratsUser user, String token) {
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user