Back

Sign-up error: how to get fix this appwriteExecption:

  • 0
  • React Native
  • Apple
  • Auth
Fabiosky
11 Feb, 2025, 12:23

const submit = async () => { if (form.username === "" || form.email === "" || form.password === "") { Alert.alert("Error", "Please fill in all fields"); return; }

TypeScript
setSubmitting(true);
console.log("πŸš€ Attempting to create user with:", form);

try {
  const result = await createEmailUser({
    email: form.email,
    password: form.password,
    username: form.username,
  });

  console.log("βœ… User created successfully:", result);

  if (result) {
    const session = await account.createSession(form.email, form.password);
    console.log("βœ… Session created:", session);

    setUser(result);
    setIsLogged(true);

    router.replace("/");
  } else {
    Alert.alert("Error", "Sign-up failed.");
  }
} catch (error) {
  console.error("❌ Sign-up error:", error);
  Alert.alert("Error", (error as Error).message);
} finally {
  setSubmitting(false);
}

};

TL;DR
Error in sign-up process due to an Appwrite exception. The `createEmailUser` function is creating an Appwrite account with user data and storing it in a database, but encountering errors. Check the `createEmailUser` function for issues. Make sure all necessary fields are filled before creating a user. If the user creation fails, an error message is displayed. Focus on debugging this section to resolve the sign-up error.
Fabiosky
11 Feb, 2025, 12:24

export async function createEmailUser({ email, password, username }: CreateUserParams) { try { console.log("πŸš€ Creating Appwrite account...");

TypeScript
const userId = ID.unique();

const newAccount = await account.create(
  "unique()",
  email,
  password,
  username
);

console.log("βœ… Account created:", newAccount);

if (!newAccount || !newAccount.$id) {
  throw new Error("User creation failed.");
}


const avatarUrl = avatar.getInitials(username).toString();
console.log("πŸ–Ό Avatar generated:", avatarUrl);



console.log("πŸ“¦ Storing user in database...");
const newUser = await databases.createDocument(
  config.databaseId,
  config.userCollectionId,
  ID.unique(),
  {
    accountId: newAccount.$id,
    email,
    username,
    avatar: avatarUrl,
    role: "user",
  }
);

console.log("βœ… User stored in database:", newUser);

return newUser;

} catch (error) { console.error("❌ Error in createUser():", error); throw new Error(error instanceof Error ? error.message : String(error)); } }

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