To install the required dependencies navigate to the project folder and run yarn:
$ cd ~/<pathname>/Backend$ yarnFor the server to work properly you need to generate an sqlite database file on your local machine:
$ npx knex migrate:latestThis will generate an app.sqlite3 file under the database/ directory.
Then we can get the server up an running on http://localhost:5000:
$ yarn serverBy default, the /login endpoint will not work as expected because, in order to generate valid tokens, a secret must be provided. The code expects this secret to come from an environment variable.
To get the authentication logic working on your local machine, create a file in the root of the project called .env. In this file, include the following environment variables:
DB_ENV=development
SECRET=<add a random secret here>
To successfully run tests we need to generate a test sqlite database:
$ yarn testdbThis will generate an testing.sqlite3 file under the database/ directory.
To run unit tests on the code:
$ yarn test[POST] /api/auth/register
Purpose: Creates a new user on the database.
Input Fields:
{
"email": "",
"password": ""
}Required Fields: email, password.
Response:
{
"message": "Successfully created user <user_email>"
}[POST] /api/auth/login
Purpose: Authenticates an existing user.
Input Fields:
{
"email": "",
"password": ""
}Required Fields: email, password.
Response:
{
"message": "Welcome <user_email>"
}[GET] /api/auth/verify
Purpose: Checks whether a user's token is valid.
Expected Header:
Authorization: <token>
Success Response:
{
"currentUserIsVerified": true
}Failure Response:
{
"currentUserIsVerified": false
}[GET] /api/me
Purpose: Returns current user object.
Expected Header:
Authorization: <token>
Response:
{
"email": "<user_email>"
}[PUT] /api/me
Purpose: Edit current user fields.
Expected Header:
Authorization: <token>
Input Fields:
{
"<field_to_edit>": ""
}Required Fields: At least one of the following: email or password.
Response:
{
"email": "<new_user_email>"
}