Secure SMS OTP Authentication API using Node.js, Express, JWT, and Notify Africa
# Secure SMS OTP Authentication API
A robust and secure authentication system built with Node.js, Express, and MongoDB, featuring SMS-based OTP verification powered by Notify Africa's SMS gateway. This API provides user registration, login, password reset, and account verification functionality with enhanced security measures.
## Features
- 🔐 Secure user registration with phone number verification
- 📱 SMS-based OTP verification via Notify Africa
- 🔄 Password reset functionality with OTP confirmation
- 🔒 JWT-based authentication
- 👥 Role-based access control (Admin/Student)
- ⏱️ OTP expiration and rate limiting
- 🛡️ Secure password hashing with bcrypt
- 🚀 RESTful API design
## Tech Stack
- **Runtime**: Node.js
- **Framework**: Express.js
- **Database**: MongoDB with Mongoose ODM
- **Authentication**: JWT (JSON Web Tokens)
- **SMS Service**: Notify Africa API
- **Security**: bcrypt for password hashing, JWT for tokens
## Prerequisites
- Node.js (v14 or higher)
- MongoDB database
- Notify Africa API credentials (API token and sender ID)
- npm or yarn package manager
## Environment Variables
Create a `.env` file in the root directory and add the following variables:
```env
PORT=3000
DB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
NOTIFY_API_TOKEN=your_notify_africa_api_token
NOTIFY_SENDER_ID=your_sender_id (defaults to "137" if not provided)
```
## Installation
1. Clone the repository:
```bash
git clone
github.com
cd secure-sms-otp-auth
```
2. Install dependencies:
```bash
npm install
```
3. Start the development server:
```bash
npm run dev
```
Or start in production mode:
```bash
npm run serve
```
## API Endpoints
### Authentication
- `POST /api/v1/auth/register` - Register a new user
- `POST /api/v1/auth/verify-otp` - Verify OTP for registration/password reset
- `POST /api/v1/auth/resend-otp` - Resend OTP
- `POST /api/v1/auth/login` - User login
- `POST /api/v1/auth/forgot-password` - Req …