Search code examples
angularauthenticationservicerefreshpolling

Is there a way to open a window only once using angular services?


I have an Angular login service that do a lot of stuff.. and it basically refresh users credentials every X minutes. If something went wrong refreshing credentials, it opens a new AWS windows, and a new library will poll and endpoint that will return "true" if you clicked "Allow" on that windows. Basically, as it is an angular service, it will be executed for every tab, resulting in two new AWS windows if you have 2 tabs open, and so on.

Is there a way to execute it only once?

I'm opening a new windows with window.open(url). But i don't know if it is possible.


Solution

  • try to give a name to your window, it should be re-used if already opened :

    https://developer.mozilla.org/fr/docs/Web/API/Window/open

    If a window with the name already exists, then url is loaded into the existing window. In this case the return value of the method is the existing window and windowFeatures is ignored.