Offline/Online Sync in a Real World Ionic Application with CouchDB
This is supposed to be a longer description
Offline Access and Reauthentication
Allowing offline access and automatic reauthentication
PROModule Outline
- 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
Lesson Outline
Offline Access and Reauthentication
At the beginning of this module we set two requirements that we have no yet met:
- If a user has previously logged in, and they have an unexpired token, they should be automatically logged in when returning to the application
- Users should have offline access to the data in the application that syncs when online
Although we have not yet implemented this functionality, we already have most of the work done. We already store a users information in local storage when they log in, which includes a token for re-authentication, and we already have all the data we need stored locally in PouchDB, so we don't need an Internet connection to access existing data. As we have already discussed, PouchDB supports modifying data locally and syncing when online, so there's no issue there either.
We just need to make a couple of changes to the application so that the user doesn't get stuck at the login screen when they are offline and if they have already logged in and have a valid token. In order to access the application while offline the user will have to have already logged in previously while online - it's not possible to authenticate whilst offline.
Modify the Auth Service
In order to facilitate this functionality, we are going to add an additional function to our Auth service called reauthenticate
. This will attempt to make use of the user data stored in local storage to perform the authentication - if a valid token is available then the authentication will pass without having to check against the server.
Thanks for checking out the preview of this lesson!
You do not have the appropriate membership to view the full lesson. If you would like full access to this module you can view membership options (or log in if you are already have an appropriate membership).