diff --git a/angular/src/app/app.interceptors.ts b/angular/src/app/app.interceptors.ts index d1098092..0728b3fc 100644 --- a/angular/src/app/app.interceptors.ts +++ b/angular/src/app/app.interceptors.ts @@ -6,6 +6,7 @@ import { EnvService } from './services/env.service'; import { catchError } from 'rxjs/operators'; import { StreetviewAuthenticationService } from './services/streetview-authentication.service'; import { NotificationsService } from './services/notifications.service'; +import { v4 as uuidv4 } from 'uuid'; @Injectable() export class JwtInterceptor implements HttpInterceptor { @@ -37,6 +38,22 @@ export class JwtInterceptor implements HttpInterceptor { }); } + // for guest users, add a custom header with a unique id + if (!this.authSvc.isLoggedIn()) { + // Get (or create of needed) the guestUserID in local storage + let guestUuid = localStorage.getItem('guestUuid'); + + if (!guestUuid) { + guestUuid = uuidv4(); + localStorage.setItem('guestUuid', guestUuid); + } + request = request.clone({ + setHeaders: { + 'X-Guest-UUID': guestUuid, + }, + }); + } + if ( request.url.indexOf(this.envService.streetviewEnv.mapillary.apiUrl) > -1 && !(request.url.indexOf(this.envService.streetviewEnv.mapillary.tokenUrl) > -1)