Closed nicmart-dev closed 1 month ago
Prerequisite: #15
npm install google-auth-library @react-oauth/google
import { GoogleOAuthProvider, useGoogleLogin } from '@react-oauth/google';
const App = () => {
return (
<GoogleOAuthProvider clientId="YOUR_CLIENT_ID">
<Login />
</GoogleOAuthProvider>
);
};
const Login = () => {
const login = useGoogleLogin({
onSuccess: tokenResponse => {
// Handle successful login
console.log(tokenResponse);
},
onFailure: error => {
// Handle login failure
console.log(error);
},
scope: 'https://www.googleapis.com/auth/calendar.readonly',
});
return (
<button onClick={() => login()}>Sign in with Google</button>
);
};
export default App;
Integrate Google Authentication into a React application using the
@react-oauth/google
package.Prerequisite: you need to set up OAuth 2.0 authentication using the Google Auth Library in your React application, using OAuth 2.0 credentials (Client ID and Client Secret) set up in #15. This will allow users to sign in with their Google accounts.