From 5d8a2123120bcb79f58de4e8b882a454b05d1e98 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Thu, 6 May 2021 20:15:58 +0100 Subject: [PATCH] Improved the Plex OAuth flow --- .../src/app/login/login.component.ts | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Ombi/ClientApp/src/app/login/login.component.ts b/src/Ombi/ClientApp/src/app/login/login.component.ts index 5245b8239..e9260d685 100644 --- a/src/Ombi/ClientApp/src/app/login/login.component.ts +++ b/src/Ombi/ClientApp/src/app/login/login.component.ts @@ -146,6 +146,9 @@ export class LoginComponent implements OnDestroy, OnInit { } public oauth() { + if (this.oAuthWindow) { + this.oAuthWindow.close(); + } this.oAuthWindow = window.open(window.location.toString(), "_blank", `toolbar=0, location=0, status=0, @@ -159,16 +162,22 @@ export class LoginComponent implements OnDestroy, OnInit { this.authService.login({ usePlexOAuth: true, password: "", rememberMe: true, username: "", plexTvPin: pin }).subscribe(x => { this.oAuthWindow!.location.replace(x.url); - this.pinTimer = setInterval(() => { + if (this.pinTimer) { + clearInterval(this.pinTimer); + } - this.oauthLoading = true; - this.getPinResult(x.pinId); - }, 4000); + this.pinTimer = setInterval(() => { + if(this.oAuthWindow.closed) { + this.oauthLoading = true; + this.getPinResult(x.pinId); + } + }, 1000); }); }); } public getPinResult(pinId: number) { + clearInterval(this.pinTimer); this.authService.oAuth(pinId).subscribe(x => { if(x.access_token) { this.store.save("id_token", x.access_token); @@ -176,7 +185,7 @@ export class LoginComponent implements OnDestroy, OnInit { if (this.authService.loggedIn()) { this.ngOnDestroy(); - if(this.oAuthWindow) { + if (this.oAuthWindow) { this.oAuthWindow.close(); } this.oauthLoading = false; @@ -184,6 +193,10 @@ export class LoginComponent implements OnDestroy, OnInit { return; } } + this.notify.open("Could not log you in!", "OK", { + duration: 3000 + }); + this.oauthLoading = false; }, err => { console.log(err);