]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+login/login.component.ts
Add URL redirection support for external auth
[github/Chocobozzz/PeerTube.git] / client / src / app / +login / login.component.ts
index 648b8db36a8608b59f910f29efb52f68214e8b40..73bd41ab4f16b2db24e21317f2278a21a2ee54c2 100644 (file)
@@ -1,7 +1,7 @@
 
 import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core'
 import { ActivatedRoute } from '@angular/router'
-import { AuthService, Notifier, RedirectService, UserService } from '@app/core'
+import { AuthService, Notifier, RedirectService, SessionStorageService, UserService } from '@app/core'
 import { HooksService } from '@app/core/plugins/hooks.service'
 import { LOGIN_PASSWORD_VALIDATOR, LOGIN_USERNAME_VALIDATOR } from '@app/shared/form-validators/login-validators'
 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
@@ -17,6 +17,8 @@ import { RegisteredExternalAuthConfig, ServerConfig } from '@shared/models'
 })
 
 export class LoginComponent extends FormReactive implements OnInit, AfterViewInit {
+  private static SESSION_STORAGE_REDIRECT_URL_KEY = 'login-previous-url'
+
   @ViewChild('forgotPasswordModal', { static: true }) forgotPasswordModal: ElementRef
 
   accordion: NgbAccordion
@@ -46,7 +48,8 @@ export class LoginComponent extends FormReactive implements OnInit, AfterViewIni
     private userService: UserService,
     private redirectService: RedirectService,
     private notifier: Notifier,
-    private hooks: HooksService
+    private hooks: HooksService,
+    private storage: SessionStorageService
   ) {
     super()
   }
@@ -88,6 +91,8 @@ export class LoginComponent extends FormReactive implements OnInit, AfterViewIni
       this.externalAuthError = true
       return
     }
+
+    this.storage.setItem(LoginComponent.SESSION_STORAGE_REDIRECT_URL_KEY, this.redirectService.getPreviousUrl())
   }
 
   ngAfterViewInit () {
@@ -151,7 +156,9 @@ The link will expire within 1 hour.`
 
     this.authService.login(username, null, token)
       .subscribe({
-        next: () => this.redirectService.redirectToPreviousRoute(),
+        next: () => {
+          this.redirectService.redirectToPreviousRoute(this.storage.getItem(LoginComponent.SESSION_STORAGE_REDIRECT_URL_KEY))
+        },
 
         error: err => {
           this.handleError(err)