How to detect when user closes or cancels Apple Music authorization

I have a web app that will pop up an Apple Music authorization window when the following code is run:


  const handleAppleMusicAuthorize = async () => {
    try {      
      await window.MusicKit.getInstance().authorize();
     // do stuff
    } catch (error) {
      console.warn("Error authorizing apple music", error);
    }
  };


If the user successfully authorizes the app, all is good; however, if the user closes the pop-up or cancels the process, there is no feedback for the app to detect.


I was thinking of using a timeout, but that seems ineligant.


What's the best way to handle this?


Any advice would be appreciated.

Just a note on this, in that I discovered that if the user clicks "Not now", there will be an error "1" thrown and received by the app, which can then be handled.


The closure of the pop-up window, apparently won't be observable, so my current work-around is to have a cancel button on the page from which the authorize method is called, which resets things from the user's perspectiv.

How to detect when user closes or cancels Apple Music authorization
 
 
Q