X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Blogin%2Flogin.component.ts;h=96754b7824791b6e25a2405e1316963490c1b252;hb=13e7c3b02a265d2b8ecd1db65b0ae24fdfd620b4;hp=648b8db36a8608b59f910f29efb52f68214e8b40;hpb=0882c8e6509b2a4ea48f6c48ecb2aa4aa371500a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+login/login.component.ts b/client/src/app/+login/login.component.ts index 648b8db36..96754b782 100644 --- a/client/src/app/+login/login.component.ts +++ b/client/src/app/+login/login.component.ts @@ -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 { ActivatedRoute, Router } from '@angular/router' +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,9 @@ 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, + private router: Router ) { super() } @@ -88,6 +92,11 @@ export class LoginComponent extends FormReactive implements OnInit, AfterViewIni this.externalAuthError = true return } + + const previousUrl = this.redirectService.getPreviousUrl() + if (previousUrl && previousUrl !== '/') { + this.storage.setItem(LoginComponent.SESSION_STORAGE_REDIRECT_URL_KEY, previousUrl) + } } ngAfterViewInit () { @@ -151,7 +160,15 @@ The link will expire within 1 hour.` this.authService.login(username, null, token) .subscribe({ - next: () => this.redirectService.redirectToPreviousRoute(), + next: () => { + const redirectUrl = this.storage.getItem(LoginComponent.SESSION_STORAGE_REDIRECT_URL_KEY) + if (redirectUrl) { + this.storage.removeItem(LoginComponent.SESSION_STORAGE_REDIRECT_URL_KEY) + return this.router.navigateByUrl(redirectUrl) + } + + this.redirectService.redirectToLatestSessionRoute() + }, error: err => { this.handleError(err)