1.1.1 • Published 12 months ago
complete-auth v1.1.1
Complete Auth
Developer: PRAMOD THYAGARAJ
Connect
An easy-to-use module for handling user and admin authentication via email OTP. This module supports login and signup flows for both users and admins, providing a robust and secure way to manage authentication in your application.
Features
Login
Login as User:
- Users can log in using their email and a One-Time Password (OTP) sent to their email.
Login as Admin:
- Admins can log in using their email and a One-Time Password (OTP) sent to their email.
Signup
Signup as User:
- Users can sign up by entering their email and receiving an OTP to verify their account.
Signup as Admin:
- Admins can sign up by entering their email. An OTP will be sent to the super admin's email for verification before the account is created.
Setup Guide
Prerequisites
- Node.js: Ensure you have Node.js installed (>= 14.x recommended).
- npm: Ensure npm is available for managing dependencies.
Step 1: Install the Package
Install the complete-auth package via npm:
npm install complete-authStep 2: Create a .env File
In the root directory of your project, create a .env file to configure the backend API endpoint:
VITE_BACKEND_ENDPOINT=http://localhost:8000/api- Replace
http://localhost:8000/apiwith your actual backend API URL.
Step 3: Usage Guide
1. Import and Initialize the Module
Import the module into your application and initialize it.
import { login, signup } from "authentication-module";2. Login Functions
Login as User
login("user", {
email: "user@example.com",
otp: "123456", // OTP sent to the user's email
})
.then((response) => console.log("Login successful:", response))
.catch((error) => console.error("Login failed:", error));Login as Admin
login("admin", {
email: "admin@example.com",
otp: "123456", // OTP sent to the admin's email
})
.then((response) => console.log("Admin login successful:", response))
.catch((error) => console.error("Admin login failed:", error));3. Signup Functions
Signup as User
signup("user", {
email: "user@example.com",
})
.then((response) => console.log("Signup successful:", response))
.catch((error) => console.error("Signup failed:", error));Signup as Admin
signup("admin", {
email: "admin@example.com",
})
.then((response) => console.log("Admin signup request sent:", response))
.catch((error) => console.error("Admin signup failed:", error));Step 4: Backend API Setup
Ensure the backend API supports the following endpoints:
Endpoints
- POST
/user/login:- Handles user and admin login with email OTP.
- POST
/user/signup:- Handles user signup and sends OTP to the user's email.
- POST
user/signup/admin:- Sends an OTP to the super admin for admin account creation.
Environment Variables
| Variable | Description | Example |
|---|---|---|
VITE_BACKEND_ENDPOINT | Backend API base URL | http://localhost:8000/api |
Key Features
- Easy Integration:
- Simplifies OTP-based login and signup processes for users and admins.
- Secure:
- Ensures account verification through OTP mechanisms.
- Customizable:
- Supports environment-based configuration for different backend endpoints.
Troubleshooting
"Module not found" Error:
- Ensure the package is installed correctly using
npm install complete-auth.
- Ensure the package is installed correctly using
Backend Not Responding:
- Verify the
VITE_BACKEND_ENDPOINTin the.envfile is pointing to a valid backend API.
- Verify the
Login/Signup Fails:
- Ensure the backend API is running and properly configured to handle the respective endpoints.
Happy authenticating! 🎉