I have the following code:
console.log('Checking... ' +
auth.isAuthenticated() ?
`User ${auth.user.email} is authenticated` :
'User is not authenticated!'
);
If isAuthenticated returns false, then auth.user is undefined.
Therefore, trying to print auth.user.email when isAuthenticated==false, will result in an error.
But in my case, I only want to print auth.user.email when auth.isAuthenticated==true but I still get this error:
TypeError: Cannot read property 'email' of undefined
console.log('Checking... ' + (auth.isAuthenticated() ? `User ${auth.user.email} is authenticated` : 'User is not authenticated!') );should work.