We have been working through a simple authentication and create account flow using OvermindJS and ReactJS, using Ionic Framework React Components for the User Interface. The application covers Create Account, Save User Information, Login & Logout.
We are currently tracking the user information and the authentication status in the OvermindJS State, without managing the interaction with a real data backend which is what we are covering here. We will add a firebase api to the application and the integration point will be through effects.ts
Initialization
First for initialization, we can revisit our onInitialize function in overmind/index.ts. The call remains the same, but we will integrate firebase initialization to set the state and get the current user if necessary.
Overmind also provides a functional API to help you manage complex logic. This API is inspired by asynchronous flow libraries like RxJS, though it is designed to manage application state and effects.
Now we need to create the entry in the user collection by calling effects.createUserRecord
// effects.ts - create user recordexportconstcreateUserRecord=async (userInfo:{email:string;firstName:string;lastName:string;uid:string;})=>{returnawaitfirebaseAPI.createUserRecord(userInfo);};// firebase-data.ts - firebase create user recordexportconstcreateUserRecord=async (info:{email:string;firstName:string;lastName:string;uid:string;})=>{letusersRef=firebase.firestore().collection("users").doc(info.uid);letcreated=firebase.firestore.Timestamp.fromDate(newDate());letnewUserData={...info,created,};awaitusersRef.set(newUserData);return (awaitusersRef.get()).data();};
In the file firebase-data.ts where we create user record by adding it to the users collection; you can see in the end where we are querying the record again.
return (awaitusersRef.get()).data();
That is because we want the user record with all of the data including the timestamp which was generated by the firebase server.
Login User
This is pretty straight forward, no a use of operators, just a straight call from actions to effects to firebase api
This is the last piece of the puzzle to create the account and to work through authentication with firebase as the backend database. There certainly are additional optimizations and changes that could be made, but this was meant to be a simple introduction to the concepts.
Please checkout the associated videos on YouTube and the source code in the GitHub Repo.