Search This Blog

Saturday, October 3, 2020

SPFx- Get Current Login User Id, Email, Title

import * as angular from "angular";
import pnp, { PermissionKind } from "sp-pnp-js";

export class empController {
  public userNamestring = "";
  public CurntUserIdnumber = 17//siteadmin by default
  public static $injectstring[] = ['DataService''$window'"$scope"]; //import name based on app-mondule 
  constructor(private dataServiceDataServiceprivate $windowangular.IWindowServiceprivate $scopeng.IScope) {
    // tslint:disable-next-line: no-shadowed-variable   
    pnp.sp.web.currentUser.get().then(result => {
      this.CurntUserId = result.Id;
      
    });
    //this.$scope.$apply();     
  }
}

/*
Email:'admin@testdev.onmicrosoft.com'
Expiration:''
Id:17
IsEmailAuthenticationGuestUser:false
IsHiddenInUI:false
IsShareByEmailGuestUser:false
IsSiteAdmin:true
LoginName:'i:0#.f|membership|admin@testdev.onmicrosoft.com'
odata.editLink:'Web/GetUserById(17)'
odata.id:'https://test.sharepoint.com/sites/dev/_api/Web/GetUserById(17)'
odata.metadata:'https://test.sharepoint.com/sites/dev/_api/$metadata#SP.ApiData.Users1/@Element'
odata.type:'SP.User'
PrincipalType:1
Title:'Jai Saravanan'
UserId:{NameId: '10032000cd0feb72', NameIdIssuer: 'urn:federation:microsoftonline'}
UserPrincipalName:'admin@testdev.onmicrosoft.com'
__proto__:Object */

No comments:

Post a Comment