mirror of
https://github.com/seerr-team/seerr.git
synced 2026-05-24 08:49:59 -04:00
fix(auth): drop popup.closed check in Plex pin poll (#2941)
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user