'figma.currentUser' is possibly 'null'?

Hi,

I’m a product designer. I have a knowledge about coding a little bit. I want to build my Figma plugin.

I watched the tutorial of " Build your first plugin course".

Now I’m trying to develop the note plugin that is similar to the example of the tutorial video.

I want to input data types about user like name, photoUrl into a component instance.

But I got the error 'figma.currentUser' is possibly 'null'.

My ts code is like this.

Could you guys give me some help?

Thank your for reading.

figma.showUI(__html__)

figma.ui.resize(500,500);

figma.ui.onmessage = async(pluginMessage) => {

  await figma.loadFontAsync({family: "Pretendard", style: "Regular"});
  await figma.loadFontAsync({family: "Pretendard", style: "Bold"});

  const nodes:SceneNode[] = [];

  const PRDnoteComponent = figma.root.findOne(node => node.type == "COMPONENT" && node.name == "PRDnote") as ComponentNode;
  const newNote = PRDnoteComponent.createInstance();

  const templateTitle = newNote.findOne(node => node.name == "title" && node.type == "TEXT") as TextNode;
  const templateDescription = newNote.findOne(node => node.name == "description" && node.type == "TEXT") as TextNode;

  const username = figma.currentUser.name;
  console.log(username);

  templateTitle.characters = pluginMessage.title;
  templateDescription.characters = pluginMessage.description;
  nodes.push(newNote);
  
  figma.viewport.scrollAndZoomIntoView(nodes);

  figma.closePlugin();

}

You are trying to access a name property that may not exist. You need to check if this property exists.

Check out these materials:

1 Like

Thanks! I’m gonna try now :slight_smile: