0
\$\begingroup\$
@PostMapping("/signin")
public ResponseEntity<?> authenticateUser(@RequestBody User user) {

    Authentication authentication = authenticationManager
            .authenticate(new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword()));

    SecurityContextHolder.getContext().setAuthentication(authentication);
    String jwt = jwtUtils.generateJwtToken(authentication);

    JSONObject obj = new JSONObject();
    obj.put("token", jwt);
    obj.put("account_status", ((User) authentication.getPrincipal()).getAccount_status());
    obj.put("role", ((List<User>) authentication.getAuthorities()).get(0));
    return new ResponseEntity<String>(obj.toString(), HttpStatus.OK);
}

Is there a better way to return token and status to frontend? Will this design pose security risk?

\$\endgroup\$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.