Skip to content

Commit

Permalink
Create a unique id for guest users (#166)
Browse files Browse the repository at this point in the history
Store in local storage and add to requests headers
  • Loading branch information
nathanfranklin authored Nov 3, 2023
1 parent 6a38193 commit e9dd0be
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions angular/src/app/app.interceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e9dd0be

Please sign in to comment.