How to get the current logged in user in Bitbucket through JavaScript?

959 views Asked by At

How can I get the current logged in user in Bitbucket via JavaScript? Or is there any alternate way of finding logged in user in Bitbucket like we find it in Jira by (AJS.params.loggedInUser)?

1

There are 1 answers

0
dvdsmpsn On

In old Stash (v3.6.x) terms this was:

require(['stash/api/util/state'], function(state) {
  console.log('Current user', state.getCurrentUser());
});

This gives an output of:

{
  "id": 2,
  "active": true,
  "name": "david",
  "slug": "david",
  "displayName": "David Simpson",
  "avatarUrl": "https://secure.gravatar.com/avatar/********.jpg?s=48&d=mm",
  "emailAddress": "[email protected]",
  "type": "NORMAL",
  "isAdmin": true
}

For a more updated BitBucket Server this would:

require(['bitbucket/util/state'], function(state) {
  console.log('Current user', state.getCurrentUser());
});