Starts in:
0 DAY
10 HRS
43 MIN
4 SEC
Starts in:
0 D
10 H
43 M
4 S
Open Closed

Can not call app service from Angular #668


User avatar
2
hung.nguyen created
  • ABP Framework version: v4.0.0
  • UI type: Angular
  • Tiered (MVC) or Identity Server Seperated (Angular): no
  • Exception message and stack trace: N/A
  • Steps to reproduce the issue: N/A

Hi,

I have an appservice like this:

    public class UserRoleAppService : StaffAppAppService, IApplicationService
    {
        private ICurrentUser _currentUser;
        private CurrentUser _currentUser1;
        private IdentityUserManager _userManager;

        public UserRoleAppService(ICurrentUser currentUser, CurrentUser currentUser1, IdentityUserManager userManager)
        {
            _currentUser = currentUser;
            _currentUser1 = currentUser1;
            _userManager = userManager;
        }

        public async Task AssignRoleToCurrentUser(string roleName)
        {
            var currentUserEntity = await _userManager.GetByIdAsync(_currentUser.Id.Value);
            await _userManager.SetRolesAsync(currentUserEntity, new[] { roleName });
        }
    }

When I run the asp app, I see the new API

Then in Angular app, I try to call it:

    this.restService.request<any, void>({
      method: 'POST',
      url: `/api/app/user-role/assign-role-to-current-user`,
      body: { roleName: 'STAFF'},
    });

But when I set breakpoint in method AssignRoleToCurrentUser, it is not hit. Seems that the method is not called. (There is no any request in tab Network of Chrome debugger) What do I do wrong here, please help?

  • ** Another question is, when I use swagger to make the request, then in method AssignRoleToCurrentUser I see that currentUser is totally empty. How to fix that to get the currentUser?

3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Another question is, when I use swagger to make the request, then in method AssignRoleToCurrentUser I see that currentUser is totally empty. How to fix that to get the currentUser?

    Have you logged in and get the token in swagger ?

    https://github.com/abpframework/abp/pull/6124

  • User Avatar
    0
    hung.nguyen created

    If I don't login, then I can invoke the AssignRoleToCurrentUser. But if I login, then it will return 400

    About the link you send, I checked but I don't know how to make the modal appear like in the screenshots. Please guide me in more details.

    Many thanks

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    This is a known issue: https://github.com/abpframework/abp/pull/6649

    You need to open /account/login page again when you logined. now you can use swagger UI.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06