I've created this service to handle auth and it is working fine...
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { tap } from 'rxjs/operators';
import { Storage } from '@ionic/storage';
import { EnvService } from './env.service';
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class AuthService {
isLoggedIn = false;
token:any;
constructor(
private storage:Storage,
private http: HttpClient,
private env: EnvService,
) { }
login(email: String, password: String) {
let formData = {
usuario : email,
senha : password,
retsession : true
}
return this.http.post(this.env.API_URL+'/login', formData).pipe(
tap(response => {
var token = ('jwt' in response) ? response.jwt : null ;
this.storage.set('token', token)
.then(
() => { console.log('Token Stored: ' + token); },
error => console.error('Error storing item', error)
);
this.token = token;
this.isLoggedIn = true;
return token;
}),
);
}
}
Even it is working, I'm getting a compile error
[ng] ERROR in src/app/services/auth.service.ts(36,52): error TS2339: Property 'jwt' does not exist on type 'never'.
This error is on the line when I check if my token is present in http response data...
What is the correct way to check this avoiding this error?