To get Current user details in jhipster

Forums Open Source JHipster Discussion To get Current user details in jhipster

This topic contains 0 replies, has 1 voice, and was last updated by  Balvinder Singh 1 year ago.

  • Author
    Posts
  • #2987 Score: 0 | 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: