To get Current user details in jhipster

  • Creator
  • #2987 Reply
    Balvinder Singh

    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


    For Id : userService.getUserWithAuthorities().get().getId()
    For Name : userService.getUserWithAuthorities().get().getFirstName()
    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….

Viewing 1 reply thread
  • Author
    • #128792 Reply
      Balvinder Singh

      Case 1 – yes, you can call userWithAuthorities to get the current logged in user.

      Case 2 – this method works on JWT, so if all users are logged in but have different credentials, you will get the user using the resource.

      Here you can check updated methods User Service Jhipster


    • #127650 Reply

      Please excuse my questions if they’re dummy:

      – Case 1 : I have an entity that i’m updating in EntityResource does this method give the User who is actually using the resource?

      – Case 2 : If i have many user connected and using the same resource (EntityResource update) will this work properly and for each session, provide the corresponding user?

Viewing 1 reply thread
Reply To: To get Current user details in jhipster
Your information: