Master ReactJS Part 4 MFurqan Riaz
Master ReactJS Part 4 MFurqan Riaz
Legal Notice:
Disclaimer Notice:
omissions, inaccuracies .
OceanofPDF.com
Hashing passwords using bcryptjs in node js| Complete
React Course Article #49
Creating Login Endpoint & sending auth token| Complete
Hashing passwords using bcryptjs in nodejs| Complete React
Course Article #49 React Course Article #50
Creating a middleware to decode user from a JWT |
Complete React Course Article #51
Fetching all notes & Adding a Note | Complete React Course
Article #52
Updating an existing Note | Complete React Course Article
#53
Endpoint for deleting a Note | Complete React Course Article
#54
iNotebook React Project Setup | Complete React Course
Article #55
Creating Navbar and Routes | Complete React Course Article
#56
Introduction to React Context API | Complete React Course
Article #57
useContext hook: Using React Context API | Complete React
Course Article #58
OceanofPDF.com
Hashing Passwords using
bcryptjs in NodeJs |
Complete React Course
Article #49
In the previous article, we learned the concept of Password
Hashing, Salt and Pepper. In this article, we will implement
Password Hashing using bcryptjs in Nodejs. So without
further ado let’s begin:
Installing bcryptjs package
Bcryptjs is a nodejs package that will help us in
implementing password Hashing, salt and pepper in Nodejs
easily. To install bcryptjs you can use the below command -
npm i bcryptjs
Using bcryptjs
Bcrypt works in two regular steps. In the first step, we will
generate the salt and secondly, we will hash the password
with the generated salt.
1. Generating Salt
OceanofPDF.com
Creating Login Endpoint &
sending auth token|
Complete React Course
Article #50
In the previous article, we have sent an auth token to one of
our endpoints. In this article, we will add a new endpoint to
authenticate a user in the auth.js file. So, let’s dive straight
into it:
Authenticate a User
Till now, we have created a signup user endpoint in
"auth.js". In a similar fashion, we are going to create a login
endpoint to authenticate the user as shown below:
In Thunderclient:
OceanofPDF.com
Fetching all notes &
Adding a Note | Complete
React Course Article #52
In the previous article, we have created a middleware and a
new endpoint to fetch the details of a user with the help of a
JWT token. In today’s video, we will be creating a 'add
Notes' and 'fetchallNotes' endpoint. So, without further ado
let’s begin:
Creating a new Route - Fetch All
Notes
Now, we will be creating a new 'fetchallNotes' route, which
will provide the client with all the notes of him/her, by
fetching them from the database. Remember, it will be
providing the notes to only those clients who are logged in.
We would be using get requests as we have to simply take
the token from the header.
Result: You must have noticed that here we are getting the
empty array as a response. This happens as no notes are
available at this instance. However, if notes were available
then all the notes would have been shown as a response.
Associating the Notes with User
We would like to show the notes, stored in the database of
the iNotebook application, of the client to him/her only to
maintain and protect the privacy of the user. To add this
functionality in the application, we have to somehow
associate the Notes with the user. Here’s how we are gonna
do that:
Figure 1.3: Associate the Notes with User
Here, as a result, all the notes of the specific user have been
successfully fetched.
OceanofPDF.com
Updating an existing Note
| Complete React Course
Article #53
In the earlier videos, we have learnt how to create notes
and save them in the database of the iNotebook application.
In today’s video, we will be learning how to update an
existing note. So, without further ado let’s begin:
Creating Route - Updating Note
We will be creating a new endpoint that will help us to
update an existing note in the database. Remember, that
we will make sure that the user is logged in for accessing
the update Note endpoint. To create a new route follow the
below steps:
OceanofPDF.com
Endpoint for deleting a
Note | Complete React
Course Article #54
In the previous article, we have created an Update Note
endpoint. In this article, we will create an endpoint for
deleting a Note. So, without further ado let’s begin:
Creating Route - Delete Note
We will create the delete Note endpoint in a similar way, as
we have created the update Note endpoint. Remember,
here we will be using the ‘delete’ request method in place of
‘put’ request as shown below:
Result: Here, as you can clearly see, our notes have been
successfully deleted. Now, if the client tries to delete the
same note twice they will face an error, as the note has
been already deleted.
So, here we complete the 54th article of this React series. In
the upcoming articles, we will begin working on the client-
side and would be understanding some more new concepts
of React.
OceanofPDF.com
iNotebook React Project
Setup | Complete React
Course Article #55
In the previous article, we finally finished setting up the
backend of the iNotebook application. From now on, let
begin setting up the frontend and connect it with the
created backend of the iNotebook application. So, without
further ado let’s begin:
Getting Started with Frontend
Firstly, we will completely set up the front end of the
iNotebook app. After that, in the upcoming articles, we will
connect the backend with the frontend to complete our
iNotebook application. Let’s install some npm package in
the package.json of react application.
npm i react-router-dom
OceanofPDF.com
Creating Navbar and
Routes | Complete React
Course Article #56
In the previous article, we have begun setting up the front
end of our React App. Let’s continue the journey by creating
Navbar and Routes for our iNotebook application. So,
without further ado let’s begin:
Adding Bootstrap to our React App
(iNotebook)
In the Documentation of Bootstrap, we will find the starter
template which has two main things to add bootstrap in our
application.
1. Bootstrap bundle with popper: It contains the
Jquery files, Bootstrap.js, and popper.js files. Copy the
code and paste it inside the body tag of index.html of
the react application.
2. Bootstrap CSS: It contains the CSS files to enhance
your application. Simply, Copy the code of Bootstrap
CSS and add it inside the head tag of Index.html (In the
Public folder) of the iNotebook application.
Now, we can easily use the components of Bootstrap in our
Application. Remember the following points while copying
the code from bootstrap in the react application:
● Close those tags which don't have a closing tag.
● Replace the ‘class’ keyword with ‘ClassName’.
● Replace href= “#” with href= “/”
● The code must be in one tag or use a JSX fragment.
Note: In this tutorial, we will be moving quickly while
setting up some basic things in the iNotebook application,
as we have already learned the basics while creating the
TextUtils and NewsMonkey application.
Creating components
We are creating a components folder, in which we will
create the following components :
OceanofPDF.com
Introduction to React
Context API | Complete
React Course Article #57
In the previous article, we have begun working with the
front end of the iNotebook application. In today’s video, we
would be learning about context API, which helps a react
developer in managing complex applications. So, without
further ado let’s begin!
Why use Context API?
At a very high level, A react app consists of ‘state’ and
‘components’. As we already know that every component in
React has its own state. Due to this reason, building and
managing a complex application that has a large number of
states and components isn’t an easy task. We can resolve
this issue with the help of state lifting technique as
mentioned below:
Understanding State Lifting
In a layman language, this simply means sharing a state
from one common source. State lifting is accompanied by
lifting the state to the parent component as a source to pass
the state to the children components.
Figure 1.1: Performing State Lifting
OceanofPDF.com
useContext hook: Using
React Context API |
Complete React Course
Article #58
In the previous article, we understood the need and working
of the Context API. In this article, we will be using Context
API with the help of useContext hook. So, without further
ado let’s begin!
The Context API - Recall
The Context API can be used to share data with multiple
components, without having to pass data through props
manually. Any state inside a context will become accessible
to every component of the React Application. Now, let’s
begin working with Context API.
Getting Started - Context API
We will create a context folder in Src folder, to store all the
context of the iNotebook application. After that, we will
create a Notes sub folder, which will contain all the context
related to Notes. Finally, we will be creating some files
named NoteState.js and noteContext.js. Remember, with
the help of these two files we will be using and
understanding context API in this article.
Creating Context - In noteContext.js
First of all, we have to import createContext in the file by
using the import command. After that, we will be creating a
new context with the help of a predefined syntax and finally,
we will export the note context as shown in the below
figure:
Figure 1.1: Creating Context - In noteContext.js
OceanofPDF.com