This is a side project to create a user authentication application with React. We will rebuild a project developed by Ryan Chenkie for a course on JWT on Frontend Masters. This frontend application will rely on an API built by following that same course, which can be found in this repository.
To build the application I followed the wonderful course taught by Brian Holt at Frontend Masters as a complete introduction to React and its ecosystem. You can find his course notes here.
Following that track, this app has been built starting from the simplest React application possible. Its first working version (check the commit after the initial one) only uses two script tags to load the React and the ReactDOM libraries (their development versions) from a CDN.
All the tools have been configured manually, instead of using a black box like create-react-app
.
To run this application, you need to have Node.js installed. If you don't have it, please go to the Node.js website, download and install it.
Then you can install this application, by (forking and) downloading it and then running the command npm install
from your terminal.
Run the app by using the script command npm run start:dev
from the command line and open your browser at localhost:8080
to see it live.
Watch Webpack live update your output without you having to reload your browser window, while in development, after we added the Hot Module Replacement feature (and its plugins built for React).
- React - A JavaScript library for building user interfaces
- Reach Router - Next generation routing for React
- Bootstrap 4 - Frontend component library
- reactstrap - Easy to use React Bootstrap 4 components
- Jest - Delightful JavaScript Testing
- Webpack - A static module bundler for modern JavaScript applications
- Daniele Erbì - daniel-234
This application has been built based on these repositories: React User Authentication, Complete Intro to React v4 and Testing Workshop. The full courses based on these repositories can be found on Frontend Masters.
This application uses Bootstrap 4 as a library for custom components. Consider switching or using Material-UI to build React components that implement Google's Material Design.
The ESLint configuration rules used in this project are the ones suggested by Brian Holt in his workshop notes: ESLint and React configuration.
With the addition of a configuration file for Webpack, there's no need to specify manually an entry point or an output on the command line, as we already did that in that configuration file.
This project uses Webpack development server, that conveniently provides live reloading. It serves its assets from the configured public path property, so a minor refactoring has been done in commit 2b8c7a9653
.
That little modification in index.html
let us load the main.js
file from that folder, instead of doing it from the home page.
Errors in this configuration may lead to several issues (see Webpack and HMR issues to read more).
The bundled file referenced inside the home page now has a relative path that points to the folder where the development server accesses the webpack assets.
Part of this small project, built to learn how to deal with authentication, consists on working on protecting routes. Assigning priviledges to certain users would require a management service, that is beyond the scope of this small project. So I've created an 'augmented' signup method that you can use to play with the application with admin credentials. As a user with 'admin' credentials, you can add instructors to the database. If you want to register a user with admin credentials, just uncomment the 'signupAdmin' method in the 'login' component and comment the 'signup' method (and viceversa to create a normal user).
This application uses two services for Continuous Integration:
This project is intended for learning purposes only. Much of it will reproduce code found in the repositories listed in Notes, so if you intend to use it, please refer to their original licenses and give appropriate credit to the respective authors.
-
39Digits - Configure Prettier and ESLint in Visual Studio Code
-
39Digits - Automatically format your JavaScript commits using Prettier, Husky and lint-staged
-
Dan Abramov - issue in ESLint: React is defined but never used
-
Dan Abramov on Medium - Lint like it's 2015 - (Use a preset to have React specific linting rules for ESLint).
Useful links for issues related to Webpack configuration (especially when it's configured to work with a dev server or on hot module reloading) and a router, be it React Router or Reach Router.
The first link helps to point to a solution of the issue of not being able to navigate to any route different from the serving URL ("/" path).
-
Stackoverflow - React Router V4 - cannot GET URL
The second link is an explanation of how to fix the problem, in more detail.
-
Tyler McGinnis - React Router - cannot get URL refresh
The third link points to a problem that may arise if you don't configure your script files to be served from a relative file (see Live reloading and relative paths above).
-
Stackoverflow - Unexpected token error in React Router component
-
Stackoverflow - How to define private data with behavior delegation in JS
-
Stackoverflow - Wrapping (properly) a React Router Link in an HTML button
-
Stackoverflow - How to remove the default link color of the HTML hyperlink tag
-
Stackoverflow - How to remove the underline for anchor links
-
Stackoverflow - How do I access previous Promise results in a then chain
-
Stackoverflow - What is the correct terminology for JavaScript Promises
-
Stackoverflow - How to return from a Promise catch-then block