Skip to content

Commit

Permalink
Merge pull request #118 from taggit-tacc/task/WG-139-add-uuid-for-gue…
Browse files Browse the repository at this point in the history
…st-users

task/WG-139: add uuid for guest users
  • Loading branch information
nathanfranklin authored Nov 6, 2023
2 parents 8352334 + 35c8ce2 commit aee1c7e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/app/app.interceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Observable, throwError } from 'rxjs';
import { EnvService } from './services/env.service';
import { AuthService } from './services/authentication.service';
import { catchError } from 'rxjs/operators';
import { v4 as uuidv4 } from 'uuid';

@Injectable()
export class AuthInterceptor implements HttpInterceptor {
Expand Down Expand Up @@ -67,6 +68,22 @@ export class TokenInterceptor 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,
},
});
}

return next.handle(request);
}
}

0 comments on commit aee1c7e

Please sign in to comment.