User Registration
In this section you learn how to create a page, implement sign up, sign in and sign out to your Ionic app.
This is how it will look like:
To complete this quickstart, you need:
- An app created at Back4App.
At any time, you can access the complete Ionic Project built with this tutorial at our GItHub repository.
Considering you have an existing Ionic project, the first thing you need to do is to install parse SDK. You can do it by running:
- Open your app.component.ts, import parse and initialize its connection to Back4App Parse server.
If you don’t know how to find your keys, check out the first Ionic tutorial Start From Template.
Now, let’s create our LogIn page. Luckly, Ionic does everything to us. All we need to do is to run the following command:
In this page view, we need to add inputs for username and password and two buttons, one for signing up and another one for signing in.
Let’s implement now the methods signIn() and signUp() referred in our Login view.
Learn more about signUp() at Parse Documentation.
Learn more about Parse.User.logIn() at Parse Documentation.
This is how it should look like.
Let’s move to our HomePage (or the page the user will be directed after logging in) and implement the sign out.
First, go ahead, open home.html and add a button for doing so.
Now, let’s implement the logOut() method and also add a Toast component if the request fails.
Learn more about Parse.User.logOut() at Parse Documentation.
It should look like this.
An important feature of parse is that it remembers if a user is logged or not in a device. It means that even if the user closes the app, you can still restore his session when the app is open.
With that, we can determine if the app initial page will be our LoginPage or HomePage.
To do so, we just need to call currentAsync(). It will return the user logged in or null.
Learn more about Parse.User.currentAsync() at Parse Documentation.
At this point, just run ionic serve and you will have a sign in, sign up and sign out features working that also remembers the logged user until he/she logs out.