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
- Custom domain for Google Auth
Hello! I connected my custom domain to my Appwrite project, but I can't get the Google login/consent screen to show my domain instead of the Appwrite domain. I...
- [SOLVED] Production down - createExecuti...
Hey, Since 1.9.6 rollout in fra (~17:00 UTC, 14 Aug), POST /v1/functions/{functionId}/executions returns a 400 whenever the body includes an empty headers ob...
- Quota not resetting
hi, im using appwrite's free tier plani hit my read limts last month and the billing cycle said it would reset on june 4th but that is today, the billing cycle ...