![](https://cdn.discordapp.com/avatars/718517766268911719/46aa49739c6222e34399ae23b1cde9d6.webp)
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);
}
};
![](https://cdn.discordapp.com/avatars/718517766268911719/46aa49739c6222e34399ae23b1cde9d6.webp)
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
- Phone authentication limit for free plan
Hello everyone, I am using phone authentication to login but with the free plan it has the limit of 10 authentication only and now it is not allowing to signup ...
- OAuth Identity should not be unique
I'm working on OAuth authorization_code flow with HubSpot. The access_token and identity I get after user has been logged in are related to a HubSpot portal (wi...
- Android - Self-Hosted account.get() "nul...
Android (Kotlin) SDK 7.0.0, Self-hosted appwrite version 1.6.0 I'm using Google OAuth2 to log the user in. After they log in, I can see them in the Auth tab in...
![](/images/bgs/pre-footer.png)