1.0.1 • Published 4 months ago

delta-react-authentication v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

delta-react-authentication

A simple React authentication package that integrates with delta-authentication APIs for login, signup, and logout.

šŸ“Œ Automatically matches backend fields based on the API structure.
šŸ“Œ Stores JWT token in localStorage for session management.
šŸ“Œ Provides easy-to-use functions:

  • handleSignup(apiUrl, userData)
  • handleLogin(apiUrl, email, password)
  • handleLogout()

šŸ“Œ Installation

Install via NPM:

npm install delta-react-authentication

šŸš€ Usage

1ļøāƒ£ Setup Your Backend (delta-authentication)

Ensure you have a working backend API from delta-authentication:

POST /auth/signup
POST /auth/login
POST /auth/logout

2ļøāƒ£ Import Authentication Functions in React

import {
  handleSignup,
  handleLogin,
  handleLogout,
} from "delta-react-authentication";

const API_URL = "http://localhost:5000/auth"; // Replace with your backend URL

3ļøāƒ£ Handle Signup

āœ… Automatically detects required fields from the backend.

const signupUser = async () => {
  try {
    const response = await handleSignup(API_URL, {
      name: "John Doe",
      emailid: "john@example.com",
      age: 25,
      password: "securepass",
    });
    console.log("Signup Successful:", response);
    alert("Signup Successful!");
  } catch (error) {
    console.error("Signup Failed:", error);
  }
};

4ļøāƒ£ Handle Login

āœ… Uses emailid and password to log in.
āœ… Saves JWT token in localStorage.

const loginUser = async () => {
  try {
    const token = await handleLogin(API_URL, email, password);
    console.log("Login Successful, Token:", token);
    alert("Login Successful!");
  } catch (error) {
    console.error("Login Failed:", error);
  }
};

5ļøāƒ£ Handle Logout

āœ… Removes JWT token and logs out the user.

const logoutUser = () => {
  handleLogout();
  alert("Logged out successfully!");
};

šŸ“œ Features

āœ… Easy Integration with delta-authentication
āœ… Automatically Matches Backend Fields
āœ… JWT Token Handling (Stored in localStorage)
āœ… Customizable Signup Fields
āœ… Works with Any React Project


šŸ“Œ Notes

  • Ensure your backend expects emailid instead of email in the request body.
  • If your backend has extra fields (e.g., address, phone), include them in handleSignup.

šŸ“œ License

This project is licensed under the MIT License.

šŸ’» Contributing

Feel free to submit issues and pull requests on GitHub.


Happy coding! šŸš€

1.0.1

4 months ago

1.0.0

4 months ago