From 2747058442736c0d56909e9c0d6937e495c89670 Mon Sep 17 00:00:00 2001 From: Nathan Franklin Date: Mon, 30 Oct 2023 16:24:37 -0500 Subject: [PATCH] Create a unique id for guest users Store in local storage and add to requests headers --- angular/src/app/app.interceptors.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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)