diff --git a/client/src/app/site/services/auth.service.ts b/client/src/app/site/services/auth.service.ts index 89156d3fc4..04c9aa24a0 100644 --- a/client/src/app/site/services/auth.service.ts +++ b/client/src/app/site/services/auth.service.ts @@ -1,5 +1,5 @@ import { EventEmitter, Injectable } from '@angular/core'; -import { Router } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { CookieService } from 'ngx-cookie-service'; import { BehaviorSubject, Observable } from 'rxjs'; import { SharedWorkerService } from 'src/app/openslides-main-module/services/shared-worker.service'; @@ -47,6 +47,7 @@ export class AuthService { public constructor( private lifecycleService: LifecycleService, private router: Router, + private activatedRoute: ActivatedRoute, private authAdapter: AuthAdapterService, private authTokenService: AuthTokenService, private sharedWorker: SharedWorkerService, @@ -106,6 +107,11 @@ export class AuthService { if (userId) { this._loginEvent.emit(); this.lifecycleService.reboot(); + const paramMap = this.activatedRoute.snapshot.queryParamMap; + if (paramMap.has(`prevUrl`) && (await this.router.navigate([paramMap.get(`prevUrl`)]))) { + return; + } + this.router.navigate([`/`]); } else { this.lifecycleService.shutdown(); diff --git a/client/src/app/site/services/openslides-router.service.ts b/client/src/app/site/services/openslides-router.service.ts index e3f929dfe5..44594a7886 100644 --- a/client/src/app/site/services/openslides-router.service.ts +++ b/client/src/app/site/services/openslides-router.service.ts @@ -72,7 +72,7 @@ export class OpenSlidesRouterService { private operator: OperatorService ) { _auth.logoutObservable.subscribe(() => { - this.navigateToLogin(); + this.navigateToLogin(true); }); router.events .pipe( @@ -100,17 +100,26 @@ export class OpenSlidesRouterService { }); } - public navigateToLogin(): void { + public navigateToLogin(logout = false): void { const url = this.router.currentNavigation()?.extractedUrl.toString() || this.router.routerState.snapshot.url; // Navigate to login if the user is not already there if (!url.startsWith(`/${UrlTarget.LOGIN}`) && !new RegExp(`^/[0-9]+/${UrlTarget.LOGIN}`).test(url)) { - this.setNextAfterLoginUrl(url); - this.router.navigate([`/`, UrlTarget.LOGIN]); + const queryParams: Record = {}; + if (!logout) { + this.setNextAfterLoginUrl(url); + if (this.preLoginRedirectUrl && this.preLoginRedirectUrl.toString() !== `/`) { + queryParams[`prevUrl`] = this.preLoginRedirectUrl; + } + } + + this.router.navigate([`/`, UrlTarget.LOGIN], { + queryParams + }); } } - public navigateAfterLogin(meetingId: number): void { + public navigateAfterLogin(meetingId?: number): void { let baseRoute: string | UrlTree = meetingId ? `${meetingId}/` : `/`; if (this.preLoginRedirectUrl) { baseRoute = this.preLoginRedirectUrl.toString();