0

I'm trying to restrict a custom WebParts properties pane based on whether a user is a member of a MS group

I have built the Graph API call etc... and it simply returns true or false.

Now I want to populate the PropertiesPane based on the promise result.

protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
     let webPartOptions: IPropertyPaneField<any>[];
     const ig:any = this.checkMSGroup()
     console.log(ig) // I can see the promise result
}

I have gone do the path of trying to get the response value and build the properties based on that.

protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
     let webPartOptions: IPropertyPaneField<any>[]; 

    const ig =  this.checkMSGroup().then(value => { 
        return  value;
      }).catch(err => {
        return err;
      });
    console.log(ig)
    
      const inGroup = async () => {
        const a = await ig;
        console.log(a)
        return a;
      };

      inGroup = inGroup();
      if(inGroup==true){
            webPartOptions = [
                   PropertyPaneTextField("title", {
                        label: "Title",
                        value: this.properties.title
                   })
            ]
       }else{
            webPartOptions = [
                   PropertyPaneLabel("title", {
                        text: "Please contact Administrator"
                   })
            ]
       }

}

but failing miserably!

Can someone please give me some pointers on how to build the properties based on the response

1
  • 1
    pro tip. Don't just say that something is "failing". Say what you expect it to do and what it's doing instead. This will help people to help you. Commented Jul 8, 2022 at 18:20

1 Answer 1

0

You've got several problems here.

You're not awaiting the call to inGroup(), so the code isn't waiting for the response.

You've declared a function using const and then you're trying to assign it to the result of a call to itself.

inGroup = inGroup();

You might want something like...

const userInGroup = await inGroup();
      if(userInGroup ==true){

But aside from all that, conditionally setting property panes seems like a bad idea. What problem are you trying to solve by doing this? If you're trying to secure something, this isn't the way to do it. It can be trivially bypassed.

Good luck

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.