OfficeDev / microsoft-teams-library-js

JavaScript library for use by Microsoft Teams apps
https://docs.microsoft.com/microsoftteams/platform/
Other
426 stars 194 forks source link

Issue Notifying Success After Logging in #669

Open cooperhurt opened 2 years ago

cooperhurt commented 2 years ago

I am having a problem when notifying Success after login. Here are the little code snippets:

NOTE: I just treid this with the latest 1.10.0 and ran into the same thing.

new Promise(async (resolve, reject) => {
            const s = document.createElement("script");
            let r = false;
            s.type = "text/javascript";
            s.src = "https://statics.teams.cdn.office.net/sdk/v1.6.0/js/MicrosoftTeams.min.js";
            s.async = true;
            s.onerror = function (err) {
                alert("There was a problem loading Teams Script....");
                console.log(err, "Error");
            };
            s.onload = s.onreadystatechange = async () => {
                if (!r && (!this.readyState || this.readyState == "complete")) {
                    r = true;
                    resolve();
                }
            };
            const t = document.getElementsByTagName("script")[0];
            t.parentElement.insertBefore(s, t);
        }).then(() => {
             microsoftTeams.initialize();
              return new Promise((resolve, reject) => {
                  microsoftTeams.authentication.authenticate({
                      url: window.location.origin + "/login",
                      width: 600,
                      height: 535,
                      successCallback: () => { alert("Success"); return resolve(this.initialize()); },
                      failureCallback: (err) => { alert("error " + err); reject()}
                  });
              });
        });

Then after logging in I do:

    <script type="text/javascript">
        (function () {
            microsoftTeams.authentication.notifySuccess()
        })();
    </script>

Then my alert message says: "CancelledByUser err"

I did not close the window, but rather it should be a sucess (it actualy automatically closes the window after the success but reports it back as Cancelled.

Looks like the common problems are:

  1. Different domains between the login (not applicalbe, since I'm doing 'window.location.origin'.
  2. Calling Initilize multiple times, possible, I actually removed the initialize before notifySuccess and tried:
    <script type="text/javascript">
        (function () {
                      microsoftTeams.initialize();
              return new Promise((resolve, reject) => {
                 microsoftTeams.authentication.notifySuccess()
              });
        })();
    </script>

Appreciate any insight.

ghost commented 2 years ago

Hi cooperhurt! Thank you for bringing this issue to our attention. We will investigate and if we require further information we will reach out in one business day. Please use this link to escalate if you don't get replies.

Best regards, Teams Platform

Meghana-MSFT commented 2 years ago

We have a bug raised for microsoftTeams.authentication.notifySuccess() causing CancelledByUser error on desktop app. Could you please confirm if you are facing this issue on Desktop only?

cooperhurt commented 2 years ago

We have a bug raised for microsoftTeams.authentication.notifySuccess() causing CancelledByUser error on desktop app. Could you please confirm if you are facing this issue on Desktop only?

I actually haven't tried on mobile yet, this is a new app I am creating, as of right now I am jsut trying this in a website browser. And then manually testing this in a website browser.

Meghana-MSFT commented 2 years ago

Can you please confirm if you are facing this issue on desktop as well?

cooperhurt commented 2 years ago

Can you please confirm if you are facing this issue on desktop as well?

Correct, do you know how long out a fix to something like this might be? Or a version of the SDK that it doesn't exist in?

Meghana-MSFT commented 2 years ago

We do not have any ETA for the fix? Also could you please share console logs from web where you get this issue?

vvolodin commented 2 years ago

I'm having the same issue on Desktop only. I've also tested Android and web - works fine there.

Meghana-MSFT commented 2 years ago

@cooperhurt - Please share logs if you are still facing the issue on web? Also Please be informed that a bug has already been raised for desktop.

cooperhurt commented 2 years ago

@Meghana-MSFT Happy to provide more logs. Not sure how, I set a debugger, the only thing it shows is 'Cancelled By User' on the error. Even after a successfull login. Which this is the same error that happens if I actually do close the popout. But also occurs if I do have a success.

image

The snippet that sends the .notifySucess() is above.

This is inside the sdk: image

Meghana-MSFT commented 2 years ago

@cooperhurt - While checking it in browser check Dev tools and share logs from there.

cooperhurt commented 2 years ago

Interesting, so I was able to test this inside my AppStudio.

I was able to confirm after some debugging indeed this is only happening on desktop app, this happens immediately.

This can probably be closed as a duplicate, but does anyone know if we can use a older or specific version to get past this for now? I messed around with a lot of different SDK versions, but still occurs, almost seems like a Team Desktop problem rather then SDK?

Meghana-MSFT commented 2 years ago

Could you please try downgrading the version to 1.3.x and check. An ICM has already been raised for the same and the team is working on the fix. We will update you on the same.

tiennguyen1293 commented 2 years ago

https://github.com/OfficeDev/microsoft-teams-library-js/issues/629