Giter Site home page Giter Site logo

sessions-workshop's Introduction

Sessions Workshop

Cookies

Goal

The goal of this workshop is to step into a small application, and implement cookie/session authentication. I have tried to remove everything that isn't directly related to sessions out of your hands. Webpack is setup. The front end is already making the request when you hit Login. Its even dumping the results of errors or successes onto the redux store! Your goal is to focus solely on the following four tasks (with some optional stretches):

A Home page component has already been built. You will need to build a second component for your authenticated page. Additionally, you will need to complete the seed file, User model, and any relevant API routes.

  1. The login form should only go to /user if a user submits a username and password that exists on a user in the database.
  2. You should build out the seed side of syncAndSeed and the rest of the User model.
  3. The /user page should not be accessible if the browser does not have a cookie of a logged in user. Further, the /user page should display information about the user - like how many times they've vistied the site.
  4. The user should be able to logout from the /user page.

Stretch Goals

  1. If you stop and restart the server, the user should still be logged in.
  2. People should be able to sign up on the front end.
  3. If a user is already logged in when they visit the site, they should be immediately brought to the /user route.

Advice

Files of interest:

  1. /server/db/models/User.js
  2. /server/db/index.js
  3. /server/index.js
  4. /client/Router.js

You really should not need to touch the other files. That doesn't mean you shouldn't read some of the ones that might help you better understand the flow. Put a console.log in the reducer if you want to look there, and you can add logs to the express routes if that helps you there.

Secondly, I've added TODO comments to areas of interest. If you search this repo, you will run into the areas I think you need to interact with.

If for some reason you need to make additional POST calls to the server from the client, I've made a utility function called postFetch.

You should absolutely take a look at Eric's videos if you feel lost on some of the core topics!

Its worth note that I've already installed express-session, but have not used it at all... Its up to you if you want to use it, but I HIGHLY RECOMMEND IT.

Thanks to some middleware in your server/index.js file, you can view each request that hits your server, using your terminal. This is helpful for debugging purposes.

Getting Started

  1. npm i
  2. npm run create:database
  • I made this as a helper, if it doesnt work, create a database however it is you do that with the name sessions-workshop.
  1. npm run start:dev
  • It may just be me, but it looks like nodemon has been having issues shutting down and not closing ports... I built a bit of stuff around trying to make sure you guys don't run into that, but if it happens, general debug steps are:
    • lsof -i :3000
    • Using that ${PID number}: kill ${PID}
    • If that doesn't work for some reason, ps aux | grep node
    • Look for the process that is using a file from this directory and now again kill ${that PID}

sessions-workshop's People

Contributors

leafoflegend avatar

Stargazers

Jonathan Arreola avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.