Storing a boolean in user preferences

default discord avatar
Tinouti
last week
1

Has anyone ever done this successfully?



I'm having the following issue when I try to do it:



setPreference('key', true);
const preference = await getPreference('key');
// preference = true (type: boolean)

setPreference('key', false);
const preference = await getPreference('key');
// preference = {value: false} (type: object)


Payload returns an object with a

value

property set to false instead of returning

false

. 🤔



I worked around it doing this:


const preference = await getPreference('key');
setPreference(preference && typeof preference === "boolean");

But I'm wondering if this behavior is a bug or if it's working as intended. 🤔

    Open the post
    Continue the discussion in Discord
    Like what we're doing?
    Star us on GitHub!

    Star

    Connect with the Payload Community on Discord

    Discord

    online

    Can't find what you're looking for?

    Get help straight from the Payload team with an Enterprise License.