Giter Club home page Giter Club logo

justalk / laboratory-react-login Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 263 KB

This project is a minimum example of how to manage a login with a session token. I wanted to create a simple tutorial for some of my colleague to understand the logic. It uses react-hook-form for managing the login form and react-cookie for managing the connection cookie.

License: MIT License

JavaScript 81.81% HTML 14.83% SCSS 3.36%
laboratory login react react-cookie react-hook-form tutorial

laboratory-react-login's Introduction

LABORATORY REACT LOGIN SESSION

Goal

This project is a minimum example of how to manage a login with a session token.

I wanted to create a simple tutorial for some of my colleague to understand the logic. It uses react-hook-form for managing the login form and react-cookie for managing the connection cookie.

Plan of the presentation

I explain with all the details how I build the project and my way of working.

Documentation

Code documentation

The jsdoc can be generated locally with the following command :

npm run build:docs

Organization

Organization of the global folder

Folder's Name Description of the folder
out The documentation generated by jsdoc
public Regroup the images and public files
src Regroup the source code

Organization of the src folder

Folder's Name Description of the folder
components Regroup the components used inside the pages
constants Regroup the exported constants
hooks Regroup the react hooks
pages Regroup the components representing the pages
services Regroup the services for calling API
styles Regroup the scss files

Development

Logic

Inside the App.js, we get the token using the useToken hook. If the token exist, we let the user going wherever he want excepted login. In case the user want to go to the login page with a valid token, we redirect him to the private dashboard. If the token does not exist, we redirect the user to the login page. The public pages does not check the token at all.

Inside the useToken, we can do 3 things, set the token, get the token and check the token. When the user successfully login, we save his token. The checkToken check that the token exist and check using the backend that this one is good (in this minimal version, I am just checking his value). In case the token has been changed manually, the token is invalid and the user is considered without a token.

Packages

  • react-app-rewired: Allow us to rewrite the config of React without ejecting the app
  • customize-cra: Allow us to rewrite the config of webpack and create module alias
  • eslint: For linting the code with EsLint
  • @babel/eslint-parser: Changing the parser for having access to eslint in babel
  • eslint-config-airbnb: For having the set of rules airbnb for eslint
  • eslint-plugin-import: For managing the alias import with eslint
  • eslint-plugin-react: For managing the react rules
  • prettier: For formating the style of the code
  • eslint-plugin-prettier: For using the prettier package with esLint
  • sass: For using the SASS css preprocessor (scss)
  • jsdoc: For managing the dev documentation of the project
  • react-router-dom: For managing the router and the path to the differents pages
  • react-helmet: For managing the meta of the differents page
  • react-cookie: For managing the cookie of the user
  • react-hook-form: For managing the login form

Running

For running the API, a single command is needed.

npm run start

Commands

  • npm run dev: Run the linter and then the project in development mode

laboratory-react-login's People

Contributors

justalk avatar

Watchers

 avatar

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.