import {Client, Account, ID, Avatars, Databases } from 'react-native-appwrite'; export const config = { endpoint: 'http://cloud.appwrite.io/v1', platform: 'com.rsrg.Resurgence', projectId: '', databaseId: '', userCollectionId: '', videoCollectionId: '', storageId: '', } const client = new Client(); client .setEndpoint(config.endpoint) .setProject(config.projectId) .setPlatform(config.platform) ; const account = new Account(client); const avatars = new Avatars(client); const databases = new Databases(client); export const createUser = async (email, password, username) => { try { const newAccount = await account.create( ID.unique(), email, password, username, ) if(!newAccount) throw Error; const avatarUrl = avatars.getInitials(username) await signIn(email, password); const newUser = await databases.createDocument( config.databaseId, config.userCollectionId, ID.unique(), { accountId: newAccount.$id, email, username, avatar: avatarUrl } ) return newUser; } catch (error) { console.log(error); throw new Error(error); } } export async function signIn(email, password) { try { const session = await account.createEmailSession(email, password); return session; } catch (error) { throw new Error(error); } }