0

How to get logged in user profile in LWC? unable to use wire method which queries profileid from user object

1 Answer 1

1

You can use wire service to get User Field Detail information such as Profile Id:

import { LightningElement,wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
import USER_ID from '@salesforce/user/Id';
import USERPROFILE_ID from '@salesforce/schema/User.ProfileId';

export default class LwcCurrentUserDetails extends LightningElement {
    currentUserProfileId;
    error;
    @wire(getRecord, { recordId: USER_ID, fields: [USERPROFILE_ID]}) 
    userDetails({error, data}) {
        if (data) {
            this.currentUserProfileId = data.fields.ProfileId.value;
           
        } else if (error) {
            this.error = error ;
        }
    }
 
}

Not the answer you're looking for? Browse other questions tagged .