'How to get current user id on Angular and Asp.Net Boilerplate?
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.
Solution 1:[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;
}
}
Solution 2:[2]
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;
Solution 3:[3]
On ABP it's different
Call
import { ConfigStateService } from '@abp/ng.core';
private configState: ConfigStateService,
And then
get currentUserId(): string {
return this.configState.getDeep('currentUser.id');
}
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 | Testador |
Solution 2 | Jacques |
Solution 3 | Ahmad Masoum |