Manually clearing all entries in browser local storage results in "Cannot read property 'indexOf' of null" when checking auth status
liam-cameron opened this issue · comments
Version info
Angular: 1.6.4
Firebase: 4.2.0
AngularFire: 2.3.0
Node: 6.7.0
Chrome: 59.0.3071.115
Issue
I am using $requireSignIn to check for protected endpoints. Works perfectly when user is logged in, and when I perform a proper logout. However, I noticed manually clearing local storage entirely will result in Cannot read property 'indexOf' of null
error. This problem does not occur when even one arbitrary entry is present in local storage.
Steps to replicate
- Log in
- Navigate to any endpoint
- Clear local storage completely (all non-angularfire entries too)
- Navigate to endpoint that uses $requireSignIn
Expected behavior
I am expecting to be routed to login and to receive Possibly unhandled rejection: AUTH_REQUIRED
error in browser console.
Actual behavior
I get navigated to protected endpoint with Cannot read property 'indexOf' of null
error in browser console.
@liam-cameron Can you create a plnkr showing this error?
@davideast Hi, I'm honestly not sure how to setup a plnkr that uses the whole firebase login procedure. But the error should be easily replicable by any endpoint the uses $requireSignIn()
like this:
resolve: {
"currentAuth": ["authService", function (authService) {
return authService.firebaseAuthObject.$requireSignIn();
}]
}
My hypothesis is that if there is no localStorage key-value pairs in the browser, the function checking for the auth token receives a null
value, and then attempts to call .indexOf()
to search for the token.
If that is the case, this bug will not really have any effect in practice, since the firebase:host:fireseed-xxxxx.firebaseio.com
key-value pair will always be in the local storage. But during development/debugging this could occur. Also, any application that forcefully clears the local storage could run into this.
Hope this helps. I apologise for not being able to provide you with a nice isolated example.
Closing as stale.