From 0c59e9a39cdab547fe8a5ee14dba7c50caee6bf5 Mon Sep 17 00:00:00 2001 From: jBalasis Date: Thu, 21 Dec 2023 14:40:07 +0200 Subject: [PATCH] fix for redirect url --- src/app/pages/landing/home/home.component.ts | 2 +- src/app/services/auth-guard.service.ts | 13 +++++++++---- src/app/services/authentication.service.ts | 10 +++------- src/app/services/usagestats.service.ts | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/app/pages/landing/home/home.component.ts b/src/app/pages/landing/home/home.component.ts index 8e7607ab2..d4b9dd35e 100755 --- a/src/app/pages/landing/home/home.component.ts +++ b/src/app/pages/landing/home/home.component.ts @@ -53,7 +53,7 @@ export class HomeComponent implements OnInit { if (this.authService.getIsUserLoggedIn()) { this.router.navigate([pageUrl]); } else { - this.authService.redirectUrl = pageUrl; + // this.authService.redirectUrl = pageUrl; this.login(); } } diff --git a/src/app/services/auth-guard.service.ts b/src/app/services/auth-guard.service.ts index 8b9fdbfff..ee23d6241 100755 --- a/src/app/services/auth-guard.service.ts +++ b/src/app/services/auth-guard.service.ts @@ -12,12 +12,17 @@ export class AuthGuardService implements CanActivate, CanLoad { canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { if ( this.authenticationService.getIsUserLoggedIn() ) { return true; } - /* If no cookie was found, clear the app's session. - The user may have logged out using another OpenAIRE portal */ - sessionStorage.clear(); + // Store the attempted URL for redirecting - sessionStorage.setItem('state.location', state.url); + if (state.url !== '/join') { + /* If no cookie was found, clear the app's session. + The user may have logged out using another OpenAIRE portal */ + sessionStorage.clear(); + this.authenticationService.redirectUrl = state.url; + sessionStorage.setItem('state.location', state.url); + } + console.log('redirect state: ' + sessionStorage.getItem('state.location')); // If we decide that in this case we will send the user back to the aai // this.authenticationService.redirectUrl = state.url; diff --git a/src/app/services/authentication.service.ts b/src/app/services/authentication.service.ts index 428b1cadb..63593e2f4 100755 --- a/src/app/services/authentication.service.ts +++ b/src/app/services/authentication.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; +import { Router } from '@angular/router'; import { HttpClient } from '@angular/common/http'; import { environment } from '../../environments/environment'; import { deleteCookie, getCookie } from '../domain/utils'; @@ -8,8 +8,7 @@ import { BehaviorSubject } from 'rxjs'; @Injectable() export class AuthenticationService { - constructor(private route: ActivatedRoute, - private router: Router, + constructor(private router: Router, private http: HttpClient) {} private apiUrl: string = environment.API_ENDPOINT; @@ -18,8 +17,6 @@ export class AuthenticationService { // store the URL so we can redirect after logging in public redirectUrl: string; - private _storage: Storage = sessionStorage; - private cookie: string = null; public isLoggedIn_ = new BehaviorSubject(false); @@ -33,7 +30,6 @@ export class AuthenticationService { if (this.redirectUrl) { const url = this.redirectUrl; this.redirectUrl = null; - console.log('stored location', url); sessionStorage.setItem('state.location', url); } else { /*sessionStorage.setItem("state.location", this.router.url);*/ @@ -108,7 +104,7 @@ export class AuthenticationService { sessionStorage.removeItem('state.location'); console.log(`tried to login - returning to state: ${state}`); if ( !this.getIsUserLoggedIn() ) { - // console.log('user hasn\'t logged in yet -- going to home'); + // console.log('user hasn't logged in yet -- redirecting to home'); this.router.navigate(['/home']); } else { this.router.navigate([state]); diff --git a/src/app/services/usagestats.service.ts b/src/app/services/usagestats.service.ts index f05a3f777..d7fefbf18 100755 --- a/src/app/services/usagestats.service.ts +++ b/src/app/services/usagestats.service.ts @@ -23,7 +23,7 @@ export class UsagestatsService { getReportResponse(page: String, pageSize: String, params: URLSearchParams): Observable { const url = `${this.apiUrl}/sushilite/getReportResults/${page}/${pageSize}?${params}`; - console.log(`knocking on: ${url}`); + // console.log(`knocking on: ${url}`); return this.httpClient.get(url, headerOptions); }