Forum

Notifications
Clear all

To get Current user details in jhipster

3 Posts
2 Users
0 Likes
64 Views
Forum 1
Posts: 41
Admin
Topic starter
(@admin)
Member
Joined: 6 years ago

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....

2 Replies
Forum 1
Posts: 41
Admin
Topic starter
(@admin)
Member
Joined: 6 years ago

Hi,
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

Thanks

Reply
Forum 3
Posts: 0
(@Anonymous)
New Member
Joined: 1 second ago

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?

Reply
Share: