Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to get current logged in user in bitbucket through javascript?

Krishna Murari January 4, 2017

This question is in reference to Atlassian Documentation: Frequently Asked Questions

How to get current logged in user in bitbucket in 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 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Johannes Heger January 5, 2017

If you wrap you JS with define(...), you can access current user from pageState.

The following example defines more libs you might need, but it's taken from real code...

define('yout/path', ['aui', 'jquery', 'underscore', 'bitbucket/util/events', 'bitbucket/util/navbuilder', 'bitbucket/util/state',
    'bitbucket/util/server', 'exports'], function (AJS, $, _, events, navBuilder, pageState, server, exports) {

    // your JS here
    // ...

    var currentUser = pageState.getCurrentUser();

}

I'm not shure if you need in atlassian-plugin.xml the bitbucket-web:global dependency:

<client-resource key="my-key" name="My Client Resources">
    <context>atl.general</context>
    <directory location="/static"/>
    <dependency>com.atlassian.bitbucket.server.bitbucket-web:global</dependency>
</client-resource>

Please hava a look also at

  1. https://developer.atlassian.com/bitbucket/server/docs/latest/reference/javascript/bitbucket_util_state.html
  2. https://developer.atlassian.com/bitbucket/server/docs/latest/ => JavaScript API

A full code example you will find here:

https://bitbucket.org/jheger/stash-mybranches (also at Marketplace)

Kind regards, Johannes

TAGS
AUG Leaders

Atlassian Community Events