'how to send password from back end (spring boot) to angular and how to decrypt it in angular

i want to generate the password of the users in the back end ,but i dont know how to send it with spring boot and decrypt it in angular (i m using bcryptpasswordencoder)

@PostMapping("/signup")
  public ResponseEntity<?> registerUser(@Validated @RequestBody SignUpRequest signUpRequest) {
    System.out.println(signUpRequest.getCin());
    if (candidatRepository.existsByCin(signUpRequest.getCin())) {
      return ResponseEntity
          .badRequest()
          .body(new MessageResponse("Error: CIN is already in use!"));
    }
    String x= Generator.generateRandomPassword(6);
    // Create new user's account
    Candidat user = new Candidat(signUpRequest.getCin(), 
               signUpRequest.getDelegation(),encoder.encode(x));
    candidatRepository.save(user);

    return ResponseEntity.ok(new MessageResponse("User registered successfully!"));
  }

Ag Service

register(user:AuthSignUp): Observable<any> {
return this.http.post(AUTH_API + 'signup', {
  cin: user.cin,
  delegation: user.delegation,
}, httpOptions);
}

Login Component

this.authService.register
      (new AuthSignUp(this.cin,this.delegation)).subscribe(
        response  => {
          console.log(response )
          this.password=response ;
          this.signUpSuccessful = true;
          this.isSignUpFailed = false;
        },
        err => {
          this.errorMessage = err.error.message;
          this.isSignUpFailed = true;
        }
      );


Solution 1:[1]

In MessageResponse class you can add a new property named data

@Getter
@Setter
class MessageResponse<T> implements Serializable{
   private String message;
   private T data;

   public MessageResponse(String message,T data){
      this.data=data;
      this.message=message;
   }

   public MessageResponse(String message){
      this.message=message;
   }

}

Now, you can pass data as any type of object since MessageResponse is a generic class . In this case this data will be String

return ResponseEntity.ok(new MessageResponse<String>("User registered successfully!",PASSWORD WILL BE HERE));

In ui part, you can read it from property

this.password=response.data

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Velat Necmettin Kanat