'ABP: How to get the current user id?

I managed to display of the current user email, but how do I get the user id?

Template:
<div *ngIf="!hasLoggedIn">
   {{ (profile$ | async)?.email }}
</div>

TypeScript:
import { Profile, GetProfile, ProfileState, } from '@abp/ng.core';       

export class Component implements OnInit {
   @Select(ProfileState.getProfile) //State
   profile$: Observable<Profile.Response>;  //Model

   get hasLoggedIn(): boolean {
      return this.oAuthService.hasValidAccessToken();
   }

   constructor(private oAuthService: OAuthService) {}

   ngOnInit() {
   this.store.dispatch(new GetProfile()).subscribe(); //Action
   }
}

Inside app-routing.module.ts there is import ofApplicationLayoutComponent and inside there is a declaration of the variable currentUser $: Observable <ApplicationConfiguration.CurrentUser>; which is being used to display the user name in the navbar, and inside the ApplicationConfiguration models there is an Id, but I couldn't implement it as I did with email

Ps: Sorry for my English 😂



Solution 1:[1]

you can use GetCurrentLoginInformations() which resides in SessionServiceProxy. It returns an object which contains UserLoginInfoDto which contains email, name etc

Solution 2:[2]

public async Task LinkToUser(LinkToUserInput input)
{
    var loginResult = await _logInManager.LoginAsync(input.UsernameOrEmailAddress, input.Password, input.TenancyName);

    if (loginResult.Result != AbpLoginResultType.Success)
    {
        throw _abpLoginResultTypeHelper.CreateExceptionForFailedLoginAttempt(loginResult.Result, input.UsernameOrEmailAddress, input.TenancyName);
    }

    if (AbpSession.IsUser(loginResult.User))
    {
        throw new UserFriendlyException(L("YouCannotLinkToSameAccount"));
    }

    if (loginResult.User.ShouldChangePasswordOnNextLogin)
    {
        throw new UserFriendlyException(L("ChangePasswordBeforeLinkToAnAccount"));
    }

    await _userLinkManager.Link(GetCurrentUser(), loginResult.User);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aashir
Solution 2 zaerymoghaddam