public ResponseEntity<?> authenticateUser(@RequestBody User user) {

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

    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?



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.