- Source Code & Resources PRO
- Lesson 1: Introduction PUBLIC
- Lesson 2: Application Requirements PUBLIC
- Lesson 3: A Brief Introduction to NoSQL PUBLIC
- Lesson 4: Introduction to CouchDB PRO
- Lesson 5: Introduction to PouchDB PRO
- Lesson 6: Structuring Data in CouchDB PRO
- Lesson 7: Installing CouchDB Locally PRO
- Lesson 8: Adding Data to Futon PRO
- Lesson 9: Starting the Application PRO
- Lesson 10: Setting up the Basic User Interface PRO
- Lesson 11: Using Design Documents to Create Views in CouchDB PRO
- Lesson 12: Getting Data From CouchDB into Ionic PRO
- Lesson 13: Using Node, Express, and SuperLogin PRO
- Lesson 14: Login and Registration PRO
- Lesson 15: Offline Access and Reauthentication PRO
- Lesson 16: Advanced Form Validation PRO
- Lesson 17: Restricting Document Updates PRO
- Lesson 18: Filtering Data from CouchDB PRO
- Lesson 19: Improving User Experience PRO
- Lesson 20: Migrating to Production PRO
- Lesson 21: Conclusion PRO
We are going to need to set up a simple server in order to handle registration and authentication in our application. To begin with, we will just run this server locally like we are doing with the CouchDB database, but eventually, we will host it somewhere so that it can be accessed remotely (not just from your computer).
We are going to be creating a simple Node/Express server for the application. There will be very little code required to get the server set up, and we are also able to use a package called SuperLogin that is going to make our lives a lot easier. SuperLogin will basically handle everything we need to do for creating and authenticating users with CouchDB. We will need to perform just a little bit of configuration for SuperLogin on our server, and then it will expose a bunch of different routes that we can use to perform various actions (like
register, and so on).
In my opinion, it's generally a good idea to let someone else handle the authentication portion of your application. Authentication/authorisation is complicated and there are a lot of potential security concerns, so unless you really know what you are doing I don't think it's a good idea to create your own authentication system from scratch. Cloud services are generally the best in this regard as you don't really touch any of the authentication stuff. A library like SuperLogin handles a lot of the important security implementation details for us as well, but we are still handling some of the implementation details ourselves so we need to be careful.
We will be using a little bit of NodeJS code to create this server, but I don't intend to teach the basics of Node in this module. It will certainly be useful to have a basic understanding of Node, but you will be able to progress through these steps just fine even if you don't.
In order to set up the server, you will need to create a new folder outside of your existing Ionic project. You can create this folder wherever you like but typically people will create a project with two folders: a client folder to contain the front end (the Ionic project) and a server folder to contain the server.
Create a server folder outside of your Ionic project to contain your server
npm initinside of the server folder to initialise a Node project (you can just leave most of the fields blank)
Run the following command to install all of the dependencies:
npm install cors del dotenv express https method-override morgan @sl-nx/superlogin-next @sl-nx/couch-pwd
To make sure that things remain steady when deployed, we are going to specify a Node version in the
package.json file as well as adding a
start script. Your final
package.json should look something like this: