Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task/WG-139: add uuid for guest users #118

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading