Add Current User Metadata Boolean Type

it's probably a small number of scenarios that use it and even smaller that could be affected but the difference between "true", true, 1, 999, "false", false and 0 can cause problems on the implementation side. if the designer named the attribute something like "is_valid" and a someone tries to implement it they'd fully expect a boolean value and receiving any of the others can cause completely different results making a bug that's difficult to track down.

right now only Number and String seem to be allowed in the metadata. this covers most cases, and you can easily represent bools with the string equivilant or with 0 and non-zero but things can get confusing going this route and in code you have to remember to always handle w care.

I defined an attribute named auto_navigate and gave it a value of true, however in code this is read as "true".... this took me a while to notice and the solution needs to be implemented everywhere this attribute is used: {{ Boolean(current_user.metadata.auto_navigate) }}

this is the easiest solution, but its dependent on an overloaded constructor implementation.... in general safe, but in some scenarios not guaranteed and could infact be a potential risk if implementations change between browsers and/or versions.

the better solution is 0 and non-zero but using these values (even if you stick to only 0 and 1) aren't exactly obvious that they're meant to represent true or false when just looking at the users data... it could potentially be the index to an array w destinations to navigate to or it could be true/false. the only way to know how to use this attributes value is to look at previous implementations otherwise its too ambiguous.

2 Likes