To get Current user details in jhipster

  • Creator
    Topic
  • #2987 Reply
    Balvinder Singh
    Keymaster

    Hey there if you want to know how to get user details in Jhipster . Check this

    1. First import UserService in your class

    2. Then declare variable

    Private UserService userService

    3. Initialize in constructor

    class_constructor( UserService userService){
    this.userService = userService;
    }

    4. Then You can access details like this using getter values

    userService.getUserWithAuthorities().get().fieldName()

    For Id : userService.getUserWithAuthorities().get().getId()
    For Name : userService.getUserWithAuthorities().get().getFirstName()
    userService.getUserWithAuthorities().get().getLastName()
    For Email : userService.getUserWithAuthorities().get().getEmail()
    For Username(login) : userService.getUserWithAuthorities().get().getlogin()

    This way you can access current logged in user Details.

    You can use these values by setting directly or creating variables:

    String userEmail = userService.getUserWithAuthorities().get().getEmail()

    For any queries comment below….

Reply To: To get Current user details in jhipster
Your information:




This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. AcceptRead More