OfficeDev / office-js-helpers

[ARCHIVED] A collection of helpers to simplify development of Office Add-ins & Microsoft Teams Tabs
MIT License
126 stars 56 forks source link

TypeError: Cannot read property 'displayDialogAsync' of undefined #88

Open binarykitchen opened 6 years ago

binarykitchen commented 6 years ago

This error happens when I want to test authentication on https://localhost:3443 for an add-in I'm developing locally:

screen shot 2018-05-15 at 11 21 38

Any clues what it is?

binarykitchen commented 6 years ago

So, Office.context.ui is undefined. Hmmm, but Office-JS is loaded fine.

blandine commented 6 years ago

This error happens when trying to use authenticator.authenticate(OfficeHelpers.DefaultEndpoints.Microsoft, false) in a Dialog. For example, when trying to follow the recommended workflow : https://docs.microsoft.com/en-us/office/dev/add-ins/design/authentication-patterns :

  1. In add in, the user clicks on a button to authenticate
  2. It open a first dialog box to provide two ways of authentication
  3. The user clicks on "Sign in with Microsoft"

At this point, the office-js-helpers authenticator is called and it tries to open a new Dialog. But it's already in the previous Dialog context, therefore, Excel context is not available anymore.

After reading the code, my pov is : office-js-helpers should know that it's running in a Dialog and launch a web window instead. I don't know exactly how to check it, maybe around getHostInfo() of office-js-helpers/src/helpers/utilities.ts ? Or is there an other way?