delta-react-authentication v1.0.1
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 ofemail
in 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! š