User Authentication: Register & Login using JWT in NextJs & MYSQL
In the earlier tutorial, you learnt data migration to synchronize Sequelize model with MYSQL database . This tutorial teaches you authentication using JWT (JSON Web Token) with MYSQL database. The app allows a user to simply register an account using username, email, and password. The password is encrypted using bcryptjs . A successful registration will create a new record in users table of the MYSQL database. To log in, the app requires a user to input username and password. After successful login, the app generates a token on server using jsonwebtoken . Then the token is returned to the client and stored at the client side using js-cookie for further API access. Run the following commands to install bcrypt, jsonwebtoken, and js-cookie: npm install bcrypt jsonwebtoken js-cookie We build login and registration forms using reactstrap components. Thus, install the following dependencies: npm install bootstrap reactstrap In this project, we use axios to access ser...