Getting Current user Id on page component

cancel
Showing results for 
Search instead for 
Did you mean: 
os_cerna
Active Member

Getting Current user Id on page component

Jump to solution

Hello everyone,

Im working on an ADF app which connects to my ECM repository, the purpose of the app is to have a more responsive alternative to consumers so the can view and download documents even on their cellphones, for this i have created a custom page component for each site on my repository, and on the home page i want to display the links for the sites which the current user has access to, but for this i use this api AlfrescoApiService..getInstance().core.sitesApi.getSiteMember(sitename, userId ) and i need to somehow obtain the id of the user that has accessed the app,

Any help would be appreciated,

Thanks a lot

1 Solution

Accepted Solutions
dvuika
Alfresco Employee

Re: Getting Current user Id on page component

Jump to solution

The "alfresco-js-api" version is outdated. I believe storing logged in usernames for process/content services was added in 1.5.0. Could you please update it to "1.5.0" and run "npm install" once again?

View solution in original post

8 Replies
dvuika
Alfresco Employee

Re: Getting Current user Id on page component

Jump to solution

You can try using "AlfrescoAuthenticationService" if you want to get access to current username. The service exposes a method "getEcmUsername".

export class MyComponent {
  constructor(private authService: AlfrescoAuthenticationService) {}

  myMethod() {
    console.log(
      this.authService.getEcmUsername()
    );
  }
}
os_cerna
Active Member

Re: Getting Current user Id on page component

Jump to solution

Hi, thanks for the reply,

like you suggested i tried using AlfrescoAuthenticationService but it doesnt seem to recongise the current user logged in, here is what my code is like:

but i am getting undefined as a result, do you know why could have happened?

thanks

dvuika
Alfresco Employee

Re: Getting Current user Id on page component

Jump to solution

It should return value for logged in user. Are you sure you are logged in at the time of ngOnInit call or your HomeComponent?

os_cerna
Active Member

Re: Getting Current user Id on page component

Jump to solution

When i inspect the page it gives me this result

the login was succesful and the true value was the result of "console.log(this.authService.isLoggedIn());"

the undefined value is the result of asking the current logged user

dvuika
Alfresco Employee

Re: Getting Current user Id on page component

Jump to solution

What versions of the JS-API and ADF components you are using?

os_cerna
Active Member

Re: Getting Current user Id on page component

Jump to solution

I´m using the community edition version 5.2, also checking the versions.json of my adf app i get this:

"alfresco-js-api": {
"version": "1.4.0",
"from": "alfresco-js-api@~1.4.0",
"resolved": "https://registry.npmjs.org/alfresco-js-api/-/alfresco-js-api-1.4.0.tgz"
},

"ng2-alfresco-core": {
"version": "1.5.0",
"from": "ng2-alfresco-core@1.5.0",
"resolved": "https://registry.npmjs.org/ng2-alfresco-core/-/ng2-alfresco-core-1.5.0.tgz"
},
"ng2-alfresco-login": {
"version": "1.5.0",
"from": "ng2-alfresco-login@1.5.0",
"resolved": "https://registry.npmjs.org/ng2-alfresco-login/-/ng2-alfresco-login-1.5.0.tgz"
},

dvuika
Alfresco Employee

Re: Getting Current user Id on page component

Jump to solution

The "alfresco-js-api" version is outdated. I believe storing logged in usernames for process/content services was added in 1.5.0. Could you please update it to "1.5.0" and run "npm install" once again?

os_cerna
Active Member

Re: Getting Current user Id on page component

Jump to solution

That worked, thanks a lot