However, I am having some trouble getting consistent results, especially when testing locally, in that the user function sometimes returns null, which should not be possible?
The below code snippet should simply log to the console.
function showUserInfo() {
console.log('Booyah user is:',user);
}
Problem is that I the log shows "Booyah user is:, null"
So my questions from this snippet are:
Can I access the user object globally as the documentation suggests?
What would the circumstances be for the user object to ever be null?
The user object is available globally as a global JS variable, and so your example code should work.
You can even access it from the view XML as follows.
{$:user}
However, as you figured out, that assumes the object is being synced.
Your suggested fix will work as it will sync all user objects.
If you would prefer to only sync your own user, you can use the following sync-rules syntax instead and just add an "empty" object-specific bucket with a bucket root of self.