Skip to main content
Question

'figma.currentUser' is possibly 'null'?


nanasan

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();

}
This topic has been closed for replies.

2 replies

tank666
  • 4873 replies
  • October 31, 2023

nanasan
  • Author
  • 1 reply
  • October 31, 2023

Thanks! I’m gonna try now 🙂


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings