Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $("#auth-button").click((e) => {
- e.preventDefault();
- showLoading();
- const obj = {
- headers: { 'Authorization': 'Bearer ' + authorized.token },
- type: 'GET',
- url: `${urls[index]}authurl`,
- success: function (authUrl) {
- function messageCallback(msg) {
- //console.log("Got new window message: ", msg.data);
- if (msg.data.hasOwnProperty('success')) {
- if (msg.data.success === true) {
- $("#loggedin-response").show();
- $("#loggedin-response").html(msg.data.message);
- $('#authorized-components-container').show();
- $('#unauthorized-components-container').hide();
- $('#playlist-how-display-container').show();
- } else {
- $("#auth-response-message").html(msg.data.message);
- $("#auth-response-message").fadeIn(1000, () => {
- setTimeout(() => $("#auth-response-message").fadeOut(1000), 3000);
- });
- }
- authClosed = true;
- authWindow.close();
- hideLoading();
- window.removeEventListener('message', messageCallback);
- }
- }
- $("#loggedin-response").hide();
- $("#auth-response-message").hide();
- authClosed = false;
- const authWindow = window.open(authUrl, "_blank", "width=500,height=650");
- const authWindowInterval = setInterval(() => {
- if (authWindow.closed) {
- clearInterval(authWindowInterval);
- if (!authClosed) {
- authClosed = true;
- hideLoading();
- $("#auth-response-message").html("Auth Canceled");
- $("#auth-response-message").fadeIn(1000, () => {
- setTimeout(() => $("#auth-response-message").fadeOut(1000), 3000);
- });
- }
- }
- }, 100);
- window.removeEventListener('message', messageCallback);
- window.addEventListener('message', messageCallback);
- },
- error: (_, error, status) => {
- logError(_, error, status);
- hideLoading();
- }
- };
- $.ajax(obj);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement