X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Blogin%2Flogin.component.ts;h=96754b7824791b6e25a2405e1316963490c1b252;hb=13e7c3b02a265d2b8ecd1db65b0ae24fdfd620b4;hp=73bd41ab4f16b2db24e21317f2278a21a2ee54c2;hpb=cb28bb92daf1a0e123bc0144030c2bc65b865f4a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+login/login.component.ts b/client/src/app/+login/login.component.ts index 73bd41ab4..96754b782 100644 --- a/client/src/app/+login/login.component.ts +++ b/client/src/app/+login/login.component.ts @@ -1,6 +1,6 @@ import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core' -import { ActivatedRoute } from '@angular/router' +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' @@ -49,7 +49,8 @@ export class LoginComponent extends FormReactive implements OnInit, AfterViewIni private redirectService: RedirectService, private notifier: Notifier, private hooks: HooksService, - private storage: SessionStorageService + private storage: SessionStorageService, + private router: Router ) { super() } @@ -92,7 +93,10 @@ export class LoginComponent extends FormReactive implements OnInit, AfterViewIni return } - this.storage.setItem(LoginComponent.SESSION_STORAGE_REDIRECT_URL_KEY, this.redirectService.getPreviousUrl()) + const previousUrl = this.redirectService.getPreviousUrl() + if (previousUrl && previousUrl !== '/') { + this.storage.setItem(LoginComponent.SESSION_STORAGE_REDIRECT_URL_KEY, previousUrl) + } } ngAfterViewInit () { @@ -157,7 +161,13 @@ The link will expire within 1 hour.` this.authService.login(username, null, token) .subscribe({ next: () => { - this.redirectService.redirectToPreviousRoute(this.storage.getItem(LoginComponent.SESSION_STORAGE_REDIRECT_URL_KEY)) + 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 => {