Future<void> main() async {
/// 1. create project and collections
/// Collections
/// Address(String city)
/// Contact(String, name, Address address)
///
/// 2. Activate document security
/// 3. In collections settings of Contact: activate "CREATE" for all users
///
/// 4. Create user
/// 5. create Address
/// 6. Add "READ" permission for user to created address
final client = Client(endPoint: "https://cloud.appwrite.io/v1")
..setProject(projectId);
final account = Account(client);
final database = Databases(client);
try {
await account.get();
} catch (e) {
await account.createEmailSession(email: email, password: password);
}
final documentList = await database.listDocuments(
databaseId: databaseId,
collectionId: addressCollection,
);
final address = documentList.documents.first;
print(address);
final newContact = {"name": "new contact", "address": address.data};
final response = await database.createDocument(
databaseId: databaseId,
collectionId: contactCollection,
documentId: ID.unique(),
data: newContact,
);
// AppwriteException: user_unauthorized, The current user is not authorized to perform the requested action. (401)
print(response);
}