Appwrite - Build Fast. Scale Big. All in One Place.
Appwrite is a backend platform for developing Web, Mobile, and Flutter applications. Built with the open source community and optimized for a developer experience in the coding languages you love.
This video series will cover
login ( Part I )
logout ( Part I )
create account ( Part I )
re establish previous session ( Part I )
add documents ( Part II )
list documents ( Part II )
subscribe to events when collection is updated (Part III )
upload images( Part III )
associate images with documents( Part III )
In this first video we will show step by step how to get started with Appwrite Cloud using Vue JS Ionic Framework & Capacitor including login, logout, and creating an account, working with Appwrite Cloud Instance.
To modularize the code, we will be creating composables to manage integration with the Appwrite Web SDK.
useAppwrite
useAccount
useDatabases
useStorage
Ionic Framework components are used to create the mobile interface and Ionic Capacitor will be used to package the web application for deployment on to mobile devices.
Video
Code Changes
useAppwrite composable
created ref for appwrite databases object
create CONFIG object to export DATABASE_ID and COLLECTION_ID
the template for the component follows the pattern used in all of the other modals in the application; get information from input elements and return then values by emitting an onClose event.
in this video we are only capturing the title and the description.
<template><ion-modal:is-open="isVisible"@willDismiss="emit('onClose', null)"><ion-header><ion-toolbar><ion-buttonsslot="start"><ion-button@click="doSave">SAVE</ion-button></ion-buttons><ion-title>CREATE NEW ITEM</ion-title><ion-buttonsslot="end"><ion-button@click="emit('onClose', null)">CANCEL</ion-button></ion-buttons></ion-toolbar></ion-header><ion-content:fullscreen="true"><ion-item><ion-labelposition="stacked">Title</ion-label><ion-inputref="titleRef"type="text"placeholder="Title"></ion-input></ion-item><ion-item><ion-labelposition="stacked">Description</ion-label><ion-inputref="descriptionRef"type="text"placeholder="Description"></ion-input></ion-item></ion-content></ion-modal></template>
the script section of the component sets up the event for sending modal payload back to HomePage for processing
moved the name of the current user to the page title using the currentUser ref.
added the ADD ITEM button to the page. The button sets the value of addItemIsOpen to true which will trigger the opening of the AddItemModal component
added a section to the template to render the list of documents from the database collection. It utilizes the documents ref from that is returned from the useAppwriteDB composable
added the template code for the AddItemModal component. its has two properties isVisible which is assigned the value of addItemIsOpen and the other property is an event listener @onClose which is assigned the value of the new function doAddItem which will be called when the @onClose event is emitted from the AddItemModal component.
new import of the useAppwriteDB composable and the inclusion of functions and properties: doCreateDocument, doListDocuments, documents
added the new ref addItemIsOpen which is used for controlling the visibility of the AddItemModal
we are using an Ionic specific lifecycle event onIonViewWillEnter to reload the item documents whenever the HomePage is presented. We are doing this because when using the Ionic Vue Router the components remain in the DOM so the normal onMounted lifecycle event is only called once. We also used the composable function doListDocuments to update the property documents
We also call doListDocuments to update the property documents when the user first logs in to get all of the documents for the display
added function doAddItem which calls the composable function doCreateDocument to create a document from the AddItemModal payload that is return from the onClose event
<scriptsetuplang="ts">import{IonContent,IonHeader,IonPage,IonTitle,IonToolbar,IonButton,alertController,onIonViewWillEnter,IonList,IonItem,IonLabel}from"@ionic/vue";import{ref}from"vue";import{useAppwriteAccount}from"../composables/useAppwriteAccount";import{useAppwriteDB}from"../composables/useAppwriteDB";importCreateAccountModalfrom"../components/CreateAccountModal.vue";importLoginModalfrom"../components/LoginModal.vue";importAddItemModalfrom"@/components/AddItemModal.vue";import{Models}from"appwrite";const{createAccount,getCurrentUser,login,logout}=useAppwriteAccount();const{doCreateDocument,doListDocuments,documents}=useAppwriteDB();constcurrentUser=ref();constcreateAcctIsOpen=ref(false);constloginIsOpen=ref(false);constaddItemIsOpen=ref(false);onIonViewWillEnter(async ()=>{if (currentUser.value){awaitdoListDocuments();}});// check for user at startupgetCurrentUser().then(async (user)=>{currentUser.value=user;awaitdoListDocuments();},(error)=>{});/**
*
* @param payload
*/constdoAddItem=async (payload:null|{title:string;description:string;file?:File})=>{addItemIsOpen.value=false;if (payload){try{constresp=awaitdoCreateDocument(payload,currentUser?.value.$id);if (resp.error)throwresp.error;console.log(resp.data);}catch (error){errorAlert("Error Creating New Item",(errorasError).message);}}};constdoLogin=async (payload:null|{email:string;password:string})=>{loginIsOpen.value=false;debugger;if (payload){try{const{email,password}=payload;constloginResp=awaitlogin(email,password);if (loginResp?.error)throwloginResp.error;currentUser.value=loginResp?.data;}catch (error){errorAlert("Error Creating Account",(errorasError).message);}}};constdoLogout=async ()=>{try{constresponse=awaitlogout();if (response?.error)throwresponse.error;currentUser.value=null;}catch (error){errorAlert("Error Logging Out",(errorasError).message);}};constdoCreateAccount=async (payload:null|{email:string;password:string;name:string})=>{createAcctIsOpen.value=false;debugger;if (payload){try{const{email,password,name}=payload;constcreateAccountResp=awaitcreateAccount(email,password,name);if (createAccountResp?.error)throwcreateAccountResp.error;constloginResp=awaitlogin(email,password);if (loginResp?.error)throwloginResp.error;currentUser.value=loginResp?.data;}catch (error){errorAlert("Error Creating Account",(errorasError).message);}}};consterrorAlert=async (title:string,message:string)=>{constalert=awaitalertController.create({header:title,message:message,buttons:["OK"],});awaitalert.present();};</script>
Whats Next
Part three will cover using Appwrite Storage to store blobs and using the javascript library to save and retrieve items from Appwrite Storage. We will also deploy the application to a native device and include Ionic Capacitor to make that happen along with including Ionic Capacitor Camera Plugin to use the native camera in the device
how to get started with Appwrite Cloud using Vue JS Ionic Framework & Capacitor including login, logout, and creating an account, working with Appwrite Cloud Instance.
Getting Started With Appwrite Cloud, Vue JS Ionic Framework & Capacitor
Appwrite - Build Fast. Scale Big. All in One Place.
Appwrite is a backend platform for developing Web, Mobile, and Flutter applications. Built with the open source community and optimized for a developer experience in the coding languages you love.
In this video, I'm going to show you how to get started with Appwrite Cloud using Vue JS Ionic Framework & Capacitor including login, logout, and creating an account, working with Appwrite Cloud Instance.
I am creating vue composables for Account and AppwriteClient. Will create them for Database and Storage in part two of the video series when I cover those topics