delta-react-authentication
v1.0.1
Published
A frontend authentication package for React using delta-authentication APIs.
Maintainers
Readme
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/logout2️⃣ Import Authentication Functions in React
import {
handleSignup,
handleLogin,
handleLogout,
} from "delta-react-authentication";
const API_URL = "http://localhost:5000/auth"; // Replace with your backend URL3️⃣ Handle Signup
✅ Automatically detects required fields from the backend.
const signupUser = async () => {
try {
const response = await handleSignup(API_URL, {
name: "John Doe",
emailid: "[email protected]",
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
emailidinstead ofemailin the request body. - If your backend has extra fields (e.g.,
address,phone), include them inhandleSignup.
📜 License
This project is licensed under the MIT License.
💻 Contributing
Feel free to submit issues and pull requests on GitHub.
Happy coding! 🚀
