Almost every website in the world has user authentication. In this project, you have to implement user authentication using the Python Flask framework for building a backend REST API and React.js, and sessionStorage API for the frontend web application.
Implement an authentication system with the following parts:
At least the following pages and React components must be implemented into the project:
Path | Component | Functionality |
---|---|---|
/signup | <Signup> | Renders the signup form |
/login | <Login> | Renders the login form |
/private | <Private> | Validates that only authenticated users can enter and renders this component |
Do not clone this repository because we are going to be using a different template.
We recommend opening the React.js + Flask API boilerplate
using a provisioning tool like Codespaces (recommended) or Gitpod. Alternatively, you can clone it on your local computer using the git clone
command.
This is the repository you need to open or clone:
1https://github.com/4GeeksAcademy/react-flask-hello
๐ Please follow these steps on how to start a coding project.
๐ก Important: Remember to save and upload your code to GitHub by creating a new repository, updating the remote (
git remote set-url origin <your new url>
), and uploading the code to your new repository using theadd
,commit
andpush
commands from the git terminal.
Usually, an authentication system is implemented in 4 parts:
At the beginning of every application, there are no users or tokens, so the first step that makes sense to build is user signup.
/signup
path./signup
and match it with its corresponding React.js page component, which will take care of rendering the signup HTML.onSubmit
event; it gets triggered and the handleSubmit
function fetches the email and password to the backend Python Flask API, probably doing a POST /token
request with the email and password on the body's payload.This part of the process occurs only when new tokens have to be generated.
myapplication.com/login
path./login
path and match it with its corresponding React.js page component; this page will take care of rendering the login form.token
object.sessionStorage
./private
.This process occurs when the user desires to logout.
onClick
event handler is called.sessionStorage
.Any user can just type /private
to attempt visiting a private page. That is why we need to implement a validation that prevents anonymous users from seeing the content of this page, and we must redirect the user to /login
or any other public page. This is usually how the process goes:
myapplication.com/private
./private
and match it with its corresponding React.js page component that will take care of rendering the HTML.sessionStorage
contains the authenticated token. You normally would do that in the useEffect
because you want to do it very early during the application loading.sessionStorage
๐ does not have the token, the current user is not considered to be logged in and the component must redirect to the login view.sessionStorage
๐ does contain the token, the current user is successfully logged in, and the rest of the /private
view component is loaded.This and many other projects are built by students as part of the 4Geeks Academy Coding Bootcamp by Alejandro Sanchez and many other contributors. Find out more about our Full Stack Developer Course, and Data Science Bootcamp.