This is a small application built to manage user authentication and two-factor authorization using Node.js, MongoDB, GraphQL, and JWT. The application allows users to register, change their password, and log in using two-factor authentication.
- Make sure you have Node.js and npm installed on your system.
- Clone this repository:
git clone https://github.com/shamkhall/auth-app-two-factor
- Navigate to the project directory:
cd auth-app-two-factor
- Install dependencies:
npm install
- Ensure that you have MongoDB installed and running on your system.
- Edit
.env.example
file as needed. - Run the application:
npm start
Users can register by providing their email and password. The data is stored securely in MongoDB.
Users can change their password after logging in with their email and password.
Upon successful authentication, users receive a JWT token that grants them access to protected resources.
Users can generate a QR code containing a secret key that is associated with their account for two-factor authorization.
Users must enter their password and a one-time code generated from the QR code to successfully log in.
The application provides a GraphQL API using Apollo Server for registration, login, get all users, password change, and two-factor authorization operations.
The project follows a clean and organized structure:
auth-app-two-factor/
├── src/
│ ├── auth/
│ ├── config/
│ ├── error/
│ ├── middleware/
│ ├── main.ts
├── .env.example
├── .gitignore
├── nodemon.json
├── package.json
├── package-lock.json
├── README.md
├── tsconfig.json
- User data is stored securely in MongoDB.
- JWT is used for authentication, and a secure JWT secret key is required.
- Two-factor authorization adds an extra layer of security using one-time codes.
The application adheres to SOLID principles by organizing code into separate modules and services for improved maintainability and scalability.