Giter Club home page Giter Club logo

popcornpals's People

Contributors

blindsweatyhansolo avatar

Stargazers

 avatar

Watchers

 avatar

popcornpals's Issues

Set up JWT logic

As a user, I can create an account and login

  • Use JWT to maintain logged in status.
  • A logged in user can access all features, otherwise users trying to access direct pages are redirected to the login/signup page.

Set up authentication logic in utils

  • define a token (sent via req.body/req.query/headers)
  • separate 'Bearer' from to grab token string
  • IF NO TOKEN: return request object as is
  • decode and attach user data to request object with jwt.verify
  • return updated request object

Define signToken function that expects a _username, email, id and adds them to the token with jwt.sign

NOTES

  • Make sure to hide your secret in an ENV!

Set up DB schemas/models

Models:

User

  • username
  • email
  • password
  • createdAt
  • friends
    • ref: User
  • ratedMovies
    • ref: Movie
  • suggestedMovies
    • ref: Movie
      Include virtual for friendCount

Movie

Movie schema only needs a title, all other info is pulled from calls to OMDb API to reduce collection size

  • title
  • rating
    • ref to Rating schema

Rating (Schema only)

Rating will consist of DISLIKE | LIKE | MUST SEE

  • rating
  • username

Establish DB typeDefs and resolvers for GraphQL

Set up GraphQL typeDefs and resolvers to define and handle data in the DB

resolvers

  • me
    • logged in user, JWT passed auth; see context if stuck
    • make sure to exclude user password
    • populate friends, ratedMovies, suggestedMovies
    • check out Apollo-Server-Express' AuthenticationError handling
  • users
    • find all users
    • populate friends, ratedMovies
  • user
    • find one user
    • make sure to exclude user password
    • populate friends, ratedMovies, suggestedMovies
  • movies
    • find all rated movies
    • params: username // movies saved to DB would have already been rated by at least one registered user
  • movie
    • find one movie via _id // movie data will consist of just a title, and rating, all other metadata is generated by the OMDb API

typeDefs

  • User
  • Movie
  • Rating
  • Auth
    • for JWT set up/use
    • user: User
  • Query (GET/READ)
    • me
      • returns data for logged in User
    • users
      • returns data for all Users
      • users: [User]
    • user
      • returns data for single User
      • user(username: String!): User
    • movies
      • returns data for all rated Movies for single User
      • movies(username: String!): [Movie]
    • movie
      • returns single Movie from DB
      • all instances of a Movie in the DB means it has a rating
      • _movie(id: ID!): Movie
  • Mutation (CREATE/UPDATE/DELETE)
    • login | Auth
    • addUser
      • new instance of User | Auth
    • rateMovie
      • IF movie title exists => push username and rating to Movie's rating array
      • ELSE => create new instance of Movie and push username and rating to Movie's rating array
    • suggestMovie
      • IF movie title exists => push username and rating to all selected User's suggestedMovies array
      • ELSE => create new instance of Movie and push username and rating to all selected User's suggestedMovies array
    • addFriend
    • removeFriend

NOTES

resolvers can accept four arguments (IN ORDER)

  • parent: used for nested resolvers to handle complicated actions
  • args: object of all values passed into a query/mutation request as parameters
  • context: object that allows for the same data to be accessible by all resolvers (logged in
  • status or API access token)
  • info: contains extra information about an opertations current state (advanced)

GraphQL's error handler AuthenticationError() will catch the error and send it to the client instead of causing the server to crash

Establish connection to DB

Set up server and config files to establish connection to MongoDB via Apollo Server Express

  • Express
  • import ApolloServer
  • import typeDefs and resolvers
  • create new Apollo server and pass in schema data (typeDefs / resolvers)
    • ensure every request performs an auth check and the updated request object will be passed to the resolvers as the context
  • create new instance of Apollo server with GraphQL schema
  • make sure to call the async function to start server! startApolloServer(typeDefs, resolvers);

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.