Nothing Special   »   [go: up one dir, main page]

complete-auth

1.1.1 • Public • Published

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

  1. Login as User:

    • Users can log in using their email and a One-Time Password (OTP) sent to their email.
  2. Login as Admin:

    • Admins can log in using their email and a One-Time Password (OTP) sent to their email.

Signup

  1. Signup as User:

    • Users can sign up by entering their email and receiving an OTP to verify their account.
  2. 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

  1. Node.js: Ensure you have Node.js installed (>= 14.x recommended).
  2. npm: Ensure npm is available for managing dependencies.

Step 1: Install the Package

Install the complete-auth package via npm:

npm install complete-auth

Step 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/api with 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

  1. POST /user/login:
    • Handles user and admin login with email OTP.
  2. POST /user/signup:
    • Handles user signup and sends OTP to the user's email.
  3. 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

  1. Easy Integration:
    • Simplifies OTP-based login and signup processes for users and admins.
  2. Secure:
    • Ensures account verification through OTP mechanisms.
  3. Customizable:
    • Supports environment-based configuration for different backend endpoints.

Troubleshooting

  1. "Module not found" Error:

    • Ensure the package is installed correctly using npm install complete-auth.
  2. Backend Not Responding:

    • Verify the VITE_BACKEND_ENDPOINT in the .env file is pointing to a valid backend API.
  3. Login/Signup Fails:

    • Ensure the backend API is running and properly configured to handle the respective endpoints.

Happy authenticating! 🎉

Package Sidebar

Install

npm i complete-auth

Weekly Downloads

0

Version

1.1.1

License

MIT

Unpacked Size

56.3 kB

Total Files

36

Last publish

Collaborators

  • pramodthyagaraj