JavaScript/Express-based backend API server for Quoi, my Galvanize Capstone project.
This server handles auth, users, questions and supporting resources intended for the Quoi iOS app.
The Quoi backend automatically pulls a new daily question and daily tip from it's database every day (these are chosen at random from the pool, but are the same for all users on a given day). It will not recycle and repeat any of the same questions or tips until the entire stack has been exhausted.
- npm install
- cp .env.sample .env
- createdb quoi_dev
- npm run knex migrate:latest
- npm run knex seed:run
- npm run dev
You must restart the server after reseeding the database. This means that if it is running on a service like Heroku, you must invoke this manually after seeding by using the command 'heroku restart'.
(db is created and removed automatically by tests)
- npm test
When a token is required for a route, it follows the following format:
- Requires a header with 'authorization' key with a string value that is 'Bearer ' followed by the token value
- Example: { authorization: 'Bearer eyJhbGciOiJIUz.I1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiO' }
(please note this is not an actual token)
Requires: a body with { email, password, firstname, lastname }
Returns: the user's token in a key/value object { Auth: token }
Requires: a body with { email, password }
Returns: that user's token in a key/value object { Auth: token }
Requires: a valid token from the user, body with either/both { email, password }
Returns: the user id on success
- isUser: verifies that provided token belongs to an existing user or admin in the database
- isAdmin: verifies that provided token belongs to an existing admin in the database
- matchesThisUser: verifies that the provided token matches an existing user/admin in the database, and that their id matches the userId in the requested route
- matchesThisUserOrAdmin: verifies that the provided token matches an existing user/admin in the database, and that their id matches the userId in the requested route OR that the token belongs to an admin without requiring an id match