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:
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).
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
should probably be -
(await account.get()).name
or if you console log the whole user object, whats the output?
console.log(JSON.stringify(userData, null, 2))
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.
[RESOLVED] Appwrite Auth can't resolve user's name
Recommended threads
- Use Limits
I need urgent help, i use appwrite as a chat function for my website and my mobile android application, but recently, for the past 3 months, my database reaches...
- redirect uri not working for OAuth with ...
I'm following this tutorial: https://appwrite.io/blog/post/google-oauth-expo#create-an-expo-app but im using an android development build instead. When I run h...
- Cannot use Apple Oauth2 in React Native/...
Hi! I've trying to add the Apple sign in feature into my Expo App. I followed the docs, but I still receiving the error "Cannot set 'location.href'". Can someon...