📕
Dan Fitz's Notes
  • README
  • Ai
    • Supervised Machine Learning
      • Introduction To Machine Learning
      • Regression With Multiple Input Variables
      • Classification
  • Csharp
    • C Sharp Advanced
      • Generics
      • Delegates
      • Lambda Expressions
      • Events
    • C Sharp Fundamentals
      • Intro To C
      • Primitive Types And Expressions
      • Non Primitive Types
      • Control Flow
      • Arrays And Lists
      • Working With Dates
      • Working With Text
      • Working With Files
      • Debugging Applications
    • C Sharp Intermediate
      • Classes
      • Association Between Classes
      • Inheritance
      • Polymorphism
      • Interfaces
  • Java
    • Inheritance Data Structures Java
      • Inheritance Polymorphism Using Overriding And Access Modifiers
      • Abstract Classes And Debugging
      • File I O And Exceptions
      • Collections Maps And Regular Expressions
    • Intro To Java
      • Introduction To Java Classes And Eclipse
      • Unit Testing Arrays And Array Lists
      • Static Variables Methods And Polymorphism Using Overloading
  • Javascript
    • Algorithms Data Structures
      • Big O Notation
      • Analyzing Performance Of Arrays And Objects
      • Problem Solving Approach
      • Problem Solving Patterns
      • Recursion
      • Searching Algorithms
      • Bubble Selection And Insertion Sort
      • Merge Sort
      • Quick Sort
      • Radix Sort
      • Data Structures Introduction
      • Singly Linked Lists
      • Doubly Linked Lists
      • Stacks And Queues
      • Binary Search Trees
      • Tree Traversal
      • Binary Heaps
    • Complete Nodejs
      • Understanding Node.js
      • REST AP Is And Mongoose
      • API Authentication And Security
      • Node.js Module System
      • File System And Command Line Args
      • Debugging Node.js
      • Asynchronous Node.js
      • Web Servers
      • Accessing API From Browser
      • Application Deployment
      • Mongo DB And Promises
    • Complete React Native
      • Working With Content
      • Building Lists
      • Navigating Users Between Screens
      • State Management
      • Handling Screen Layout
      • Setting Up An App
      • More On Navigation
      • Advanced Statement Management With Context
      • Building A Custom Express API
      • In App Authentication
    • Epic React
      • React Fundamentals
      • React Hooks
      • Advanced React Hooks
      • Advanced React Patterns
      • React Performance
    • Fireship Firestore
      • Firestore Queries And Data Modeling Course
      • Model Relational Data In Firestore No SQL
    • Functional Light Javascript
      • Intro
      • Function Purity
      • Argument Adapters
      • Point Free
      • Closure
      • Composition
      • Immutability
      • Recursion
      • List Operations
      • Transduction
      • Data Structure Operations
      • Async
    • Js Weird Parts
      • Execution Contexts And Lexical Environments
      • Types And Operators
      • Objects And Functions
      • Object Oriented Java Script And Prototypal Inheritance
      • Defining Objects
    • Mastering Chrome Dev Tools
      • Introduction
      • Editing
      • Debugging
      • Networking
      • Auditing
      • Node.js Profiling
      • Performance Monitoring
      • Image Performance
      • Memory
    • React Complete Guide
      • What Is React
      • React Basics
      • Rendering Lists And Conditionals
      • Styling React Components
      • Debugging React Apps
      • Component Deep Dive
      • Building A React App
      • Reaching Out To The Web
      • Routing
    • React Testing
      • Intro To Jest Enzyme And TDD
      • Basic Testing
      • Redux Testing
      • Redux Thunk Testing
    • Serverless Bootcamp
      • Introduction
      • Auction Service Setup
      • Auction Service CRUD Operations
      • Auction Service Processing Auctions
    • Testing Javascript
      • Fundamentals Of Testing
      • Static Analysis Testing
      • Mocking Fundamentals
      • Configuring Jest
      • Test React Components With Jest And React Testing Library
    • Typescript Developers Guide
      • Getting Started With Type Script
      • What Is A Type System
      • Type Annotations In Action
      • Annotations With Functions And Objects
      • Mastering Typed Arrays
      • Tuples In Type Script
      • The All Important Interface
      • Building Functionality With Classes
    • Web Performance With Webpack
      • Intro
      • Code Splitting
      • Module Methods Magic Comments
  • Other
    • Algo Expert
      • Defining Data Structures And Complexity Analysis
      • Memory
      • Big O Notation
      • Logarithm
      • Arrays
      • Linked Lists
      • Hash Tables
      • Stacks And Queues
      • Strings
      • Graphs
      • Trees
    • Aws Solutions Architect
      • AWS Fundamentals IAM EC 2
    • Fundamentals Math
      • Numbers And Negative Numbers
      • Factors And Multiples
      • Fractions
    • Mysql Bootcamp
      • Overview And Installation
      • Creating Databases And Tables
      • Inserting Data
      • CRUD Commands
      • The World Of String Functions
      • Refining Our Selections
      • The Magic Of Aggregate Functions
    • Random Notes
      • Understanding React Hooks
  • Python
    • Data Analysis Using Python
      • Loading Querying And Filtering Data Using The Csv Module
      • Loading Querying Joining And Filtering Data Using Pandas
      • Summarizing And Visualizing Data
    • Intro To Python
      • Course Introduction Intro To Programming And The Python Language Variables Conditionals Jupyter Notebook And IDLE
      • Intro To Lists Loops And Functions
      • More With Lists Strings Tuples Sets And Py Charm
      • Dictionaries And Files
Powered by GitBook
On this page
  • Sign-up Flow
  • Sign-in Flow
  • Authenticated Endpoints Flow
  1. Javascript
  2. Complete React Native

Building A Custom Express API

Sign-up Flow

These are basic requirements to create a sign-up flow in an any backend API:

  1. Connect to a database instance.

  2. Set up a User model.

  3. Set up a POST route.

  4. In this POST route, when the user sends an email and password in the req.body, pass it into the User model and attempt to save it to the database.

  5. If any errors occur, communicate the errors back to the user.

  6. If no errors occur, use the user's email or id plus a secret key to create and send back a JSON web token for future validation.

  7. For all future authenticated routes, require the JSON web token in the payload. When you receive the token, unpack it to receive the user's email, so you know what user account is making the request.

  8. If the JSON web token fails verification (using the secret key), send back an error message. Otherwise, fulfill the request.

Note: A JSON web token is information encoded using a secret key. This encoded information is very easy to read and will often store a user's identification (like an email or username). However, it's very difficult to change this token without invalidating the identification. Think of it like a driver's license or dollar bill: it has techniques for making it easy to tell when the item is fake or not.

Sign-in Flow

  1. When the user first signs up, pass the password with a randomly generated salt appended through a hashing algorithm.

  2. Store the hashed password and the salt in the database.

  3. When the user signs in, use the plaintext password that the user sent you plus the salt in the database to re-generate the hashed password.

  4. If the generated hashed password is the same as the one stored in the database, then the user is real.

  5. Send them back a JSON web token.

Note about hashing:

  • Hashing algorithms are powerful because they are one-directional. When you give a certain input, it always spits out the same output.

  • This is useful for passwords because you can validate that the user provided the correct password without them actually telling you their password.

Note about salting:

  • Salting is a response to rainbow table attacks. A malicious user with access to your hashed passwords and who knows which hashing algorithm you used can generate a reference table of common passwords with their hashes. Using cross-reference, they can then find hashes that match the reference table, giving them the password!

  • When you salt, you essentially muddy the information. The user can't create rainbow tables as easily. They now have to account for all the salts.

  • The goal: The purpose of a salt is to make it computationally infeasible to use techniques like rainbow tables: to cut out the easy, quick options.

Authenticated Endpoints Flow

  1. In the request, user sends a JSON web token plus whatever payload is required.

  2. Server uses a middleware that runs before the endpoint to validate that the JSON web token is real.

    • Since the JSON web token has a unique identifier in it, you can use that to find the user in the database and store it in req.user for the endpoint to use.

  3. Process the request using the payload and the req.user data.

PreviousAdvanced Statement Management With ContextNextIn App Authentication

Last updated 3 years ago