2

Is there any way to get the current user on Angular using Angular + Asp.Net Boilerplate?

I know that I can get it on the API. But I want to send the object to the API with the current user id.

Testador
  • 339
  • 1
  • 3
  • 7

3 Answers3

3

On ABP it's different

Call

    import { ConfigStateService } from '@abp/ng.core';

    constructor(private configState: ConfigStateService)

And then

      get currentUserId(): string {
        return this.configState.getDeep('currentUser.id');
      }
Siphamandla Ngwenya
  • 2,696
  • 1
  • 16
  • 21
Ahmad Masoum
  • 141
  • 1
  • 9
1

On angular declare a object of UserLoginInfoDto class. initialize the object value with this.appSession.user import UserLoginInfoDto class. For example:

userLogInInfo: UserLoginInfoDto;

and in Content or View Init

this.userLogInInfo = this.appSession.user;
Jacques
  • 6,936
  • 8
  • 43
  • 102
M. Jahir
  • 11
  • 1
  • 3
1

UPDATE

I found a service where I can get user info.

@Injectable()
export class AppSessionService {

    private _user: UserLoginInfoDto;
    private _tenant: TenantLoginInfoDto;
    private _application: ApplicationInfoDto;

    constructor(
        private _sessionService: SessionServiceProxy,
        private _abpMultiTenancyService: AbpMultiTenancyService) {
    }

    get application(): ApplicationInfoDto {
        return this._application;
    }

    get user(): UserLoginInfoDto {
        return this._user;
    }

    get userId(): number {
        return this.user ? this.user.id : null;
    }

    get tenant(): TenantLoginInfoDto {
        return this._tenant;
    }

    get tenantId(): number {
        return this.tenant ? this.tenant.id : null;
    }
}
Testador
  • 339
  • 1
  • 3
  • 7
  • This doesn't compile. `_sessionService` and `_abpMultiTenancyService` are unused. `_user`, `_tenant` and `_application` are uninitialized. – Greg B Jul 05 '22 at 20:14