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

Update user using ts SDK but the username is removed

Scheduled Pinned Locked Moved Unsolved
Q&A
2
2
1.1k
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.
  • A
    altear147
    last edited by 29 Nov 2023, 11:02

    Hello guys,

    I developed the auth application using TS and fusionauth ts client SDK,

    I need to use a function update user like this

    const result = await this.fusionAuthService.editUser(body.userId, {
    email: body.email,
    firstName: body.firstName,
    lastName: body.lastName,
    mobilePhone: body.mobilePhone,
    });

    after that U check on the fusionauth dashboard, the data was updated but the username and lastLoginInstant is removed from the user so I cannot login with that user.

    lib version is "@fusionauth/typescript-client": "^1.48.0"

    Thank you for your help.

    A 1 Reply Last reply 1 Dec 2023, 10:18 Reply Quote 0
    • A
      akoskm @altear147
      last edited by 1 Dec 2023, 10:18

      @altear147 I encountered this behavior today when I tried to update the username for a user:

      await getFusionAuthClient(tenantId).updateUser(userId, {
          user: {
            username,
          },
        });
      

      To my surprise (but probably only the lack of knowledge), this set theusername of the user as specified but also deleted the email just as you described.

      I was thinking, okay, let's move on and don't touch username and specify firstName as the only key for the update:

      await getFusionAuthClient(tenantId).updateUser(userId, {
          user: {
            firstName,
          },
        });
      

      but then I received this error:
      16e0e85b-affe-4d49-be46-bf5a05f5d811-image.png

      Which I also didn't expect, since I assumed the userId uniquely identifies a user and I don't have to supply more fields to help FusionAuth identify it.

      After supplying the exact same things as you did:

      await getFusionAuthClient(tenantId).updateUser(userId, {
          user: {
            email: email as string,
            firstName: firstName as string,
            lastName: lastName as string,
            mobilePhone: mobilePhone as string,
          },
        });
      

      my user object is getting updated. To clarify, the email input is disabled on my form, and users can only enter first name, last name, and mobile phone.

      You can find the complete code here: https://github.com/akoskm/saas/blob/main/app/routes/team_.%24userId.edit.tsx

      Hope this helps.

      1 Reply Last reply Reply Quote 0
      2 out of 2
      • First post
        2/2
        Last post