Skip to content
Back

[RESOLVED] Appwrite Auth can't resolve user's name

  • 1
  • React Native
Cheese.
5 Mar, 2025, 05:56

Hi, I'm using Appwrite Auth in my iOS app. While signing up, I fetch the user's full name and pass it into the account.create() function as such:

await account.create(ID.unique(), email, password, name);

Inside my app, I want to display greetings like Good morning, {firstName}

But when I try that with this code:

TypeScript
  const [firstName, setFirstName] = useState("");

  useEffect(() => {
    const getUserData = async () => {
      try {
        const userData = await account.get();
        if (userData && userData.name) {
          // Split the name and get the first part
          const firstNameOnly = userData.name.split(' ')[0];
          setFirstName(firstNameOnly || "User");
        } else {
          setFirstName("User");
        }
      } catch (error) {
        console.error("Error fetching user data:", error);
        setFirstName("User"); // Fallback name if there's an error
      }
    };

    getUserData();
  }, []);

I always see "User", yet appwrite cloud shows the full name, separated by whitespaces, as it should be.

Also, inside the settings of my app, I want the user to be able to edit their full name so that if they want to use a nickname they can do so. I didn't find any functions that can edit the name of an user - is there any way to do this ?

I'm on expo (react native).

TL;DR
Issue: User's full name not resolved in Appwrite Auth. Solution: Ensure to fetch the user's name correctly with `(await account.get()).name`. To display greetings, split the full name and extract the first part. For editing the user's name, there isn't a built-in function, consider creating a custom solution in your app.
Cheese.
5 Mar, 2025, 05:58

i tried console.log-ing await account.get().name in many ways but it is always either empty string or the default value set by typescript

Darshan Pandya
5 Mar, 2025, 06:02

should probably be -

TypeScript
(await account.get()).name

or if you console log the whole user object, whats the output?

TypeScript
console.log(JSON.stringify(userData, null, 2))
Cheese.
5 Mar, 2025, 06:10

oh yay your console log statement helped me debug this ! thanks a lot.

I was in the wrong account which was created before I started passing the name in the account.create() function, so it had a null name.

Cheese.
5 Mar, 2025, 06:25

[RESOLVED] Appwrite Auth can't resolve user's name

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more