Skip to content

Commit c0bb15f

Browse files
committed
Bug fix:
1. Sometimes event handler getting called as soon as the popup is opened, so added a check to see if message actually contains some valid tokens 2. sometime window is also null due to this false event firing, so added check accordingly
1 parent dc3c002 commit c0bb15f

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

projects/lib/src/oauth-service.ts

+20-15
Original file line numberDiff line numberDiff line change
@@ -929,41 +929,46 @@ export class OAuthService extends AuthConfig implements OnDestroy {
929929
/**
930930
* Error handling section
931931
*/
932-
const CheckForPopupClosedInterval = 500;
932+
const checkForPopupClosedInterval = 500;
933933
let windowRef = window.open(url, '_blank', this.calculatePopupFeatures(options));
934934
let checkForPopupClosedTimer: any;
935935
const checkForPopupClosed = () => {
936936
if (!windowRef || windowRef.closed) {
937937
cleanup();
938-
reject(new OAuthErrorEvent('popup_closed',{}));
938+
reject(new OAuthErrorEvent('popup_closed', {}));
939939
}
940940
};
941941
if (!windowRef) {
942942
reject(new OAuthErrorEvent('popup_blocked', {}));
943943
} else {
944-
checkForPopupClosedTimer = window.setInterval(checkForPopupClosed, CheckForPopupClosedInterval);
944+
checkForPopupClosedTimer = window.setInterval(checkForPopupClosed, checkForPopupClosedInterval);
945945
}
946946

947947
const cleanup = () => {
948948
window.clearInterval(checkForPopupClosedTimer);
949949
window.removeEventListener('message', listener);
950-
windowRef.close();
950+
if (windowRef !== null) {
951+
windowRef.close();
952+
}
951953
windowRef = null;
952954
};
953955

954956
const listener = (e: MessageEvent) => {
955957
const message = this.processMessageEventMessage(e);
956-
957-
this.tryLogin({
958-
customHashFragment: message,
959-
preventClearHashAfterLogin: true,
960-
}).then(() => {
961-
cleanup();
962-
resolve();
963-
}, err => {
964-
cleanup();
965-
reject(err);
966-
});
958+
if (message && message !== null) {
959+
this.tryLogin({
960+
customHashFragment: message,
961+
preventClearHashAfterLogin: true,
962+
}).then(() => {
963+
cleanup();
964+
resolve();
965+
}, err => {
966+
cleanup();
967+
reject(err);
968+
});
969+
} else {
970+
console.log('false event firing');
971+
}
967972
};
968973

969974
window.addEventListener('message', listener);

0 commit comments

Comments
 (0)