I’m using a firebase backend. I’m returning a database object with the following:
return this.afDatabase.object(/users/${this.auth.uid}/settings/itineraryType);
This doesn’t work when I rotate the screen. The auth.uid loses it’s value during screen rotation. I’ve tried storing it to storage to no avail.
How do you keep the reference to a Firebase database reference on screen orientation change or app closing?
I’m not sure because while debugging in the console it works. I can see the storage has the uid but that only works while my device is plugged into my MAC. Once I unplug it from the MAC I can no longer debug and investigate. Here is the actual code.
Well I’m not certain. I just know that the UID is null and I can no longer access the database to save or retrieve the settings. I know this because before I added the storage function even in debug it wouldn’t work. I’d get an error that the UID is null.
I’m using the same examples that everyone else is using to save and retrieve data from firebase.
Thanks for responding Sujan. I actually had it all within the then but it wouldn’t work so I just started trying a bunch of different things. However, I changed it back to the following:
So then I unplugged the device from the MAC.
Closed the app then re-opened the app.
Plugged back into the MAC to view the console.
What I noticed is that I don’t think it’s hitting that if statement in getSettings() because It’s not even putting out the console.log().
And this is what’s in the console: ERROR TypeError: Cannot read property 'uid' of undefined
Please edit your post, it is not very readable at the moment.
Use the </> button above the input field to format your code, command line output or error message (select the text first, then click the button or wrap it in ``` manually). Check the preview if it looks better. This will make sure your text is readable and if it recognizes the programming language it also automatically adds code syntax highlighting. Thanks.