Within my Angular project, I have implemented authentication methods in the auth.service. The admin access token retrieved from the API is stored in a BehaviorSubject as shown below:
adminData = new BehaviorSubject(null);
saveAdminData(token:any) {
let admin:any = new AdminData(token);
this.adminData.next(admin);
}
I encountered an issue when trying to access the access_token property of the admin using the following code snippet:
this.adminData.value.access_token;
This resulted in the error message Object is possibly 'null'
. To address this, I attempted the following approach:
this.adminData.value!.access_token;
However, this led to a different error stating
Property 'access_token' does not exist on type 'never'.