export const createUser = async ({email, password, name}: CreateUserParams) => {
try{
const newAccount = await account.create(ID.unique(), email, password, name);
if(!newAccount) throw Error;
await signIn({email, password});
const avatarUrl = avatars.getInitialsURL(name);
return await database.createDocument(
appwriteConfig.databaseId,
appwriteConfig.userCollectionId,
ID.unique(),
{email, name, accountId: newAccount.$id, avatar: avatarUrl}
)
} catch(e) {
throw new Error(e as string);
}
}