Package Exports
- delta-react-google-authentication
- delta-react-google-authentication/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (delta-react-google-authentication) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
delta-react-google-authentication
Google Sign-In authentication package for React applications integrated with delta-google-authentication backend.
🚀 Installation
npm install delta-react-google-authentication📌 Setup
You need a Google OAuth Client ID and a backend API URL.
🔹 Usage
1️⃣ Import the GoogleLoginButton component
import { GoogleLoginButton } from "delta-react-google-authentication";
const Login = () => {
const handleSuccess = async (googleToken) => {
try {
const response = await fetch("http://localhost:5000/auth/google", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token: googleToken }),
});
const data = await response.json();
if (data.token) {
localStorage.setItem("backend_token", data.token); // Store backend JWT
window.location.href = "/dashboard"; // Redirect after login
}
} catch (error) {
console.error("Login failed:", error);
}
};
return (
<GoogleLoginButton
clientId="YOUR_GOOGLE_CLIENT_ID"
backendUrl="http://localhost:5000"
onSuccess={handleSuccess}
buttonText="Sign in with Google"
/>
);
};
export default Login;2️⃣ Use useGoogleAuth Hook to Get User Data
import { useGoogleAuth } from "delta-react-google-authentication";
const Dashboard = () => {
const { user, logout } = useGoogleAuth("http://localhost:5000");
return (
<div>
{user ? (
<>
<h2>Welcome, {user.name}</h2>
<img src={user.profilePic} alt="Profile" />
<button onClick={logout}>Logout</button>
</>
) : (
<p>User not logged in</p>
)}
</div>
);
};
export default Dashboard;🔹 Logout
To log out the user, call:
const { logout } = useGoogleAuth();
logout(); // Clears session📜 License
This project is licensed under the MIT License.