PWA final fix

This commit is contained in:
2023-06-24 15:35:11 +02:00
parent b858dd3e02
commit 324084fb1f
5 changed files with 31 additions and 55 deletions

View File

@@ -19,15 +19,10 @@ export class AuthInterceptor implements HttpInterceptor {
) { }
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
console.log('Welcome to interceptor:', request.url);
console.log('IsAuth?', request.url.includes('/auth/apiToken'));
if (!request.url.includes('/auth/apiToken')) {
console.log(this.auth$.expirationTime.format(), moment.utc().format());
if (this.auth$.expirationTime.isBefore(moment.utc())) {
console.log('Need to refresh token');
return this.auth$.getAPITokenObservable().pipe(
mergeMap(() => {
console.log('New token is ready');
return next.handle(request.clone({
headers: request.headers.set('Authorization', `Bearer ${this.auth$.apiToken}`),
}));
@@ -43,7 +38,6 @@ export class AuthInterceptor implements HttpInterceptor {
})
);
} else {
console.log('TOken is fine');
return next.handle(request.clone({
headers: request.headers.set('Authorization', `Bearer ${this.auth$.apiToken}`),
}));