I am working on Authentication in my project, but these two errors popped up and I am not sure what it means. This is the code in the jwt.interceptor.ts
, with the errors as comments:
import { Injectable } from '@angular/core';
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
import { Observable } from 'rxjs';
import { AuthenticationService } from './authentication.service';
@Injectable()
export class JwtInterceptor implements HttpInterceptor {
constructor(private authenticationService: AuthenticationService) { }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// add authorization header with jwt token if available
let currentUser = this.authenticationService.currentUserValue;
if (currentUser && currentUser.token) {
// ~~~~~
// error TS2339: Property 'token' does not exist on type 'Users'
request = request.clone({
setHeaders: {
Authorization: `Bearer ${currentUser.token}`
// ~~~~~
// error TS2339: Property 'token' does not exist on type 'Users'
}
});
}
return next.handle(request);
}
}
And this is the function in the token.service.ts
that corresponds to another error:
isValid() {
const token = this.get();
if (token) {
const payload = this.payload(token);
if (payload) {
return Object.values(this.iss).indexOf(payload.iss) > -1 ? true : false;
// ~~~~~~
// error TS2339: Property 'values' does not exist on type 'ObjectConstructor'.
}
}
return false;
}