Search code examples
javascriptthingsboard

Thingsboard issue: How Can I get the currently logged in user in my custom widget


I created my own custom widget. But the problem is I can't access the currently logged in user in my widget. I searched for many times but found only 1 solution.

var $injector = self.ctx.$scope.$injector;
var userService = $injector.get('userService');
var userId = userService.getCurrentUser().userId;

But this solution doesn't work for me.


Solution

  • userService will not work after TB3.0

    So you may try this:

    var user = self.ctx.currentUser;  
    console.log(user);
    

    It works well for me.