Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion client/src/app/site/services/auth.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
19 changes: 14 additions & 5 deletions client/src/app/site/services/openslides-router.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class OpenSlidesRouterService {
private operator: OperatorService
) {
_auth.logoutObservable.subscribe(() => {
this.navigateToLogin();
this.navigateToLogin(true);
});
router.events
.pipe(
Expand Down Expand Up @@ -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<string, any> = {};
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();
Expand Down
Loading