const submit = async () => { if (form.username === "" || form.email === "" || form.password === "") { Alert.alert("Error", "Please fill in all fields"); return; }
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);
}
};
export async function createEmailUser({ email, password, username }: CreateUserParams) { try { console.log("π Creating Appwrite account...");
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)); } }
Recommended threads
- Need help to create a wrapper which let ...
Iβm looking for help setting up Appwrite properly on a VPS so I can build a self-hosting wrapper around it. The goal is to provide a Linux executable that allow...
- Apple OAuth2 "Registration Not Complete"...
I'm getting a "Registration Not Complete" error when implementing Apple Sign In OAuth2 on self-hosted Appwrite. Environment: Self-hosted Appwrite (latest), iOS...
- 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...