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
- 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...
- Get Profile picture
If I made an app where user need to sign in with Google. Now how do I access the user profile picture?