FusionAuth
    • Home
    • Categories
    • Recent
    • Popular
    • Pricing
    • Contact us
    • Docs
    • Login

    Custom user data as array?

    Scheduled Pinned Locked Moved Unsolved
    Q&A
    3
    5
    3.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      minhngocnguyenduy
      last edited by

      I want to add children's data to the user, but I don't need the child's email, etc.

      I need only the child's name, date of birth, and the UUID which should be generated automatically, so I choose to use the custom user data.

      But a user can have many children and the FusionAuth custom user data does not allow me to create an array object 😞

      How could I achieve this with FusionAuth?

      M 1 Reply Last reply Reply Quote 0
      • M
        maciej.wisniowski Power User @minhngocnguyenduy
        last edited by

        @minhngocnguyenduy maybe using lambdas can help?

        danD 1 Reply Last reply Reply Quote 0
        • danD
          dan @maciej.wisniowski
          last edited by

          @maciej-wisniowski You should be able to create an array object.

          Here's a data object which should work:

          data: {
            children: [ {
              "name": "foo"
               "value": "bar"
            } ],
          }
          

          Can you please print out the JSON of the object you are trying to store in the user.data field and share it?

          --
          FusionAuth - Auth for devs, built by devs.
          https://fusionauth.io

          M 1 Reply Last reply Reply Quote 0
          • M
            minhngocnguyenduy @dan
            last edited by

            @dan When I create children by array like this

            userChildren = [{id: 'id', name: 'name', dateOfBirth: '2010-01-01'}]
            await axios.patch(
                    `${config.iamHost}/api/user/${session.userId as string}`,
                    {
                      user: {
                        email: session.user!.email!,
                        data: {
                          children: userChildren,
                        },
                      },
                    },
                    {
                      headers: {
                        "X-FusionAuth-TenantId": config.iamTenantId,
                        Authorization: config.iamApiKey,
                      },
                    }
                  );
            

            The code above did change the user custom data to

            children.id id
            children.name name
            etc
            

            I think because I didn't put the properties in the double quote as you did.

            So I have found a workaround, which is parsing it as a JSON string and later parsing it back.

            data: {
               children: JSON.stringify(userChildren),
            },
            
            danD 1 Reply Last reply Reply Quote 1
            • danD
              dan @minhngocnguyenduy
              last edited by

              @minhngocnguyenduy Glad you found a solution!

              --
              FusionAuth - Auth for devs, built by devs.
              https://fusionauth.io

              1 Reply Last reply Reply Quote 0
              • First post
                Last post