Google Sign-In authentication package for React applications integrated with delta-google-authentication
backend.
npm install delta-react-google-authentication
You need a backend running delta-google-authentication
.
import { GoogleLoginButton } from "delta-react-google-authentication";
const Login = () => {
return (
<GoogleLoginButton
backendUrl="http://localhost:5000"
buttonText="Sign in with Google"
/>
);
};
export default Login;
import { useGoogleAuth } from "delta-react-google-authentication";
const Dashboard = () => {
const { user, loading } = useGoogleAuth(backendUrl);
return (
<div>
{user ? (
<div>
<h2>Welcome, {user.name} 👋</h2>
<img src={user.profilePic} alt="Profile" />
<p>Email: {user.email}</p>
</div>
) : (
<p>User not logged in</p>
)}
</div>
);
};
export default Dashboard;
To log out the user, call:
import { useGoogleAuth } from "delta-react-google-authentication";
const Logout = () => {
const {logout } = useGoogleAuth(backendUrl);
return (
<button onClick={logout}>Logout</button>;
)};
export default Logout;
Token will be saved in localStorage as authToken.
This project is licensed under the MIT License.
Feel free to submit issues and pull requests on GitHub.
Happy coding! 🚀