After successfully creating this authentication service, everything seemed to be running smoothly...
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;
}),
);
}
}
Unfortunately, despite its functionality, I encountered a compiling error
[ng] ERROR in src/app/services/auth.service.ts(36,52): error TS2339: Property 'jwt' does not exist on type 'never'.
This issue arises when trying to verify the presence of my token within the HTTP response data...
Can anyone guide me on the correct approach to avoid triggering this error?