For this exercise, we will continue building our Pokedex web app - setting up our server to allow users to register and login with authentication.
The starter code in this repository builds upon the previous exercise's (pokedex-express).
- Fork and clone this repository to your computer
- Run
yarn install
to install dependencies - Look in the starter file called
index.js
, runnodemon
to start local server on port 3000 - Open
localhost:3000
on your browser and see the home page
The comments in this file are deliberately verbose meant to orientate you to an Express app for the first time. Feel free to remove any or all comments.
-
Expose a new endpoint that intercepts GET requests to
/users/new
, which responds with a HTML page with a new user registrationform
that has these fields:name
andpassword
-
Point the form to submit data to the route (
/users
) using POST method -
Using
bcrypt
hash the password before saving all the user data intousers.json
-
Save a cookie to record that the user is currently logged in then redirect to the root
'/'
endpoint -
Expose a new endpoint that intercepts GET requests to
/users/logout
, which clears the cookie's loggedin status and redirects to'/'
-
Expose a new endpoint that intercepts GET requests to
/users/login
, which responds with a HTML page with a user loginform
that has these fields:name
andpassword
-
Point the form to submit data to the route (
/users/login
) using POST method -
Use
bcrypt
to compare the password in theform
with the password saved in the JSON file. Save the loggedin status in the cookie and redirect to'/'
if successful
-
Show 'Hi, you're logged in!' in home only if the user is logged in
-
Show 2 buttons only if the user is not logged in: one which sends the user to the register page and another which sends them to the login page
- refactor your app to be VC (view controller) Here is a reference implementation: https://github.com/wdi-sg/express-reference/tree/mvc
- if you want to look at the changes, you can look at this link: https://github.com/wdi-sg/express-reference/compare/auth...mvc?expand=1