fix(auth): drop popup.closed check in Plex pin poll (#2941)

This commit is contained in:
Oscar White
2026-04-27 11:52:08 +01:00
committed by GitHub
parent 60a2a87a70
commit ce9643cb84

View File

@@ -122,6 +122,10 @@ class PlexOAuth {
}
private async pinPoll(): Promise<string> {
// popup.closed is unreliable under COOP same-origin-allow-popups once the
// popup navigates to app.plex.tv; bound polling by expiresAt with a 15m
// hard fallback.
const deadline = Date.now() + 15 * 60 * 1000;
const executePoll = async (
resolve: (authToken: string) => void,
reject: (e: Error) => void
@@ -140,10 +144,16 @@ class PlexOAuth {
this.authToken = response.data.authToken as string;
this.closePopup();
resolve(this.authToken);
} else if (this.popup && !this.popup.closed) {
setTimeout(executePoll, 1000, resolve, reject);
} else {
reject(new Error('Popup closed without completing login'));
const expiresAt = response.data?.expiresAt
? Date.parse(response.data.expiresAt)
: deadline;
if (Date.now() >= Math.min(expiresAt, deadline)) {
this.closePopup();
reject(new Error('Plex PIN expired before login completed.'));
return;
}
setTimeout(executePoll, 1000, resolve, reject);
}
} catch (e) {
this.closePopup();