I encountered this error message:
Error TS2304: Unable to locate the name 'ITokenResponse'.
Even after trying to import as suggested in a StackOverflow response, I encountered another error:
Error TS2306: File 'C:/Repository/MAngular/src/app/interfaceModals/ItokenResponse.ts' is not recognized as a module.
Any ideas on how I can resolve this? Here's the code snippet below. I'm currently working with Angular12. Thank you for your help!!
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {map, tap} from 'rxjs/operators' ;
import { isPlatformBrowser } from '@angular/common';
@Injectable({
providedIn: 'root'
})
export class AuthenticationService {
client_id: string = "Manage";
authKey: string ="auth";
roleKey: string="role";
constructor(private http: HttpClient, @Inject(PLATFORM_ID) private platformId:any) { }
login(username: string, password: string, userRole: string){
var data ={
username: username,
password: password,
client_id: this.client_id,
grant_type: "password",
role_name: userRole
};
this.http.post<ITokenResponse>('url', data)
.pipe(map( tkDetails => {
let checkIfTokenConditions = tkDetails && tkDetails.token;
//the above statement is lambda expresion. it checks if the
if(checkIfTokenConditions){
this.setAuth(tkDetails);
this.setRole(tkDetails.role_name);
}
return tkDetails;
}))
}