JWT Stands for (JSON Web Token) it a popular mechanism by which we can implementing authentication and authorization of a users in web applications, so basically in JWT token we store user data and the token expire time which will be in encrypted, It can be used in any application to authenticate users. Here’s how we can use JWT Web tokens in ReactJS application:
How Frontend and backend works with JWT Token
- From Frontend Application we send the login credentials using login form to the backend API server.
- Then backend API will verify the credentials passed by users exist of database, if exist then backend will generate a JWT token by storing all the user data into the token.
- Then backend API respond the JWT token back to the frontend.
- Now to keep user logged into the web application, we need to store the JWT token in browser local storage or as a cookie.
- Now whenever frontend wants some data from backend, it sends JWT token with request parameter to the backend.
- The backend verifies if the JWT token passed is valid or no, if JWT token is not expired and is valid then backend will pass the requested data back to the frontend.