In this tutorial, we will build a more practical backend-service with CONNECT and get introduced to some more nuanced details of the platform. The service we will build is a password-based authentication service.

I am assuming that you already know how to setup a CONNECT instance. If you do not know how to do that, don’t worry though: checkout connect-platform.com and you can create one with one-click.

I am also assuming that you know the core concepts of CONNECT platform. If not, take a look at this article first, and then come back.

STEP 0: Setting Up a Database

First, we need a database to store user names and passwords. For this tutorial, we will use Google’s Firestore database, which is really easy to setup and use and is free as well. Go there, and setup a new project:

fig. 1, creating a new project on Google’s firebase

Then, add a database to your project:

fig. 2, creating a Firestore database

STEP 1: Connecting to Database

Now we need to configure our CONNECT instance to enable it to talk to our database. To do that, go to the PACKAGES section of your panel, click on the circular plus button, find connect-firestore and press install:

fig. 3, how to install a package

Now we need to configure our instance to allow it to talk to our Database (obviously not everyone is allowed to talk to our database). If you click on the connect-firestore package in your packages list, you’ll see a “how to setup” button which guides you through doing just that. Basically we first need to generate a key for our database:

fig. 4, generating a key for Firestore

Now we need to give this key to our CONNECT instance. Go to the VAULT section of your panel and add a new key, naming it firestore.json :

fig. 5, adding a key to vault

For the content of the key, open the key-file you just downloaded from Firestore, and copy the contents.

Finally, we need to state in our project config that our package should use the key we just created. Go to the CONFIG section of your panel, and add the following to the JSON:

"firestore": {

"project": "connect-auth-tutorial",

"keyfile": "secure/firestore.json"

}

Which will make your configuration look like this:

fig. 6

Note that the project name should be the name of your project (you can see it under project-id in your keyfile).

STEP 2: Installing Other Packages

For a password-based authentication service, besides a database, we also need to be able to encrypt passwords and match encrypted passwords. For this purpose, go back to PACKAGES section and install connect-passwords package (which is actually a CONNECT integration for bcryptjs ).

Besides encryption, we also need to be able to create authentication tokens once a user has been authenticated. These tokens will be then used to access the resources of the user without requiring a password every time. For this purpose, connect-jwt is a really nice package to install.

So by this point, our PACKAGES section should look like this:

fig. 7, packages required for password-based authentication

We also need to have a secret that we will use to sign the aforementioned tokens, so we know that no one else can create fraudulent tokens. For this, just add the following to the CONFIG:

"secret": "some-random-string-that-is-secret"

Do not forget that the config is in JSON format, so you would need to have commas between various elements in it.

STEP 3: Registering Users