Can't check if localStorage is null/undefined

I am doing:
{{localStorage.values.authToken === null ? 'Login' : 'Logout'}}

The error is: Cannot read properties of undefined (reading 'authToken')

I also tried:

{{localStorage.values.authToken === undefined ? 'Login' : 'Logout'}}

This used to work, now it doesn't.

What am I doing wrong?

1 Like

Hi @ozgunk, you should be able to hover your mouse over the variables in a transformer to see what values it's going to give you. Here's an example of this:

It looks like on your end that authToken is not an available variable. Are you able to hover your mouse over authToken.values and see if there's an authToken available?

It looks like on your end that authToken is not an available variable

This is the point of the check; if the authToken is undefined, it should return falsey. Instead the whole evaluation crashes.

Here is a similar check I am trying to make with the same problem.
{{ (localStorage.values.myList && localStorage.values.myList[i]) ? 'REFRESH' : 'GET' }}

1 Like

Check this out