Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Brita Curum 9 posts 79 karma points
    Sep 19, 2019 @ 10:34
    Brita Curum
    0

    No data is retrieved from userService.getCurrentUser() in Umbraco V8

    Hi there,

    I am trying to get current user in the backoffice of Umbraco v8 by using userService.getCurrentUser() angular.js controller, but the function getCurrentUser() and userService are both undefined in my console.

    Could anyone please recommend the appropriate method of retrieving the user data?

    Any help is much appreciated.

    Thanks.

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Feb 14, 2021 @ 14:45
    Huw Reddick
    0

    this works for me in my customDashboard

    angular.module("umbraco").controller("CustomWelcomeDashboardController", function ($scope, userService, logResource, entityResource, contentResource) {
    
        var vm = this;
        vm.UserName = "guest";
        vm.UserLogHistory = [];
        vm.IsAdmin = false;
    
        var user = userService.getCurrentUser().then(function (user) {
            vm.UserName = user.name;
            vm.IsAdmin = user.userGroups.includes("admin");
        });
    
    ... other stuff
    
    }
    

    And in the dashboard html I display the username like so

    <h2>Welcome to Umbraco {{vm.UserName}}</h2>
    
Please Sign in or register to post replies

Write your reply to:

Draft