springreactjsspring-bootlogin-control

How does SpringBoot get current user from ReactJS?


I trying to understand the codes of Full-stack web-application at https://github.com/callicoder/spring-security-react-ant-design-polls-app but I do not understand how does spring-boot know which current user is logging in.

this is ReactJS (front-end) code that calls the api.

export function getUserCreatedPolls(username, page, size) {
    page = page || 0;
    size = size || POLL_LIST_SIZE;

    return request({
        url: API_BASE_URL + "/users/" + username + "/polls?page=" + page + "&size=" + size,
        method: 'GET'
    });
}

And, this is spring-boot(back-end) code that receives variables from front-end

@GetMapping("/users/{username}/polls")
public PagedResponse<PollResponse> getPollsCreatedBy(@PathVariable(value = "username") String username,
                                                     @CurrentUser UserPrincipal currentUser,
                                                     @RequestParam(value = "page", defaultValue = AppConstants.DEFAULT_PAGE_NUMBER) int page,
                                                     @RequestParam(value = "size", defaultValue = AppConstants.DEFAULT_PAGE_SIZE) int size) {
    return pollService.getPollsCreatedBy(username, currentUser, page, size);
}
  1. how does spring-boot get {UserPrincipal currentUser} from front-end?
  2. how does ReactJs sent {UserPrincipal currentUser} to back-end?

Solution

  • enter image description here