office-js-helpers
office-js-helpers copied to clipboard
TypeError: Cannot read property 'displayDialogAsync' of undefined
This error happens when I want to test authentication on https://localhost:3443 for an add-in I'm developing locally:

Any clues what it is?
So, Office.context.ui is undefined. Hmmm, but Office-JS is loaded fine.
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 :
- In add in, the user clicks on a button to authenticate
- It open a first dialog box to provide two ways of authentication
- 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?