nicmart-dev / linguistnow

LinguistNow simplifies the hassle of finding available linguists for translation projects.
https://linguistnow.netlify.app
1 stars 1 forks source link

Set up Google Auth Library #16

Closed nicmart-dev closed 1 month ago

nicmart-dev commented 1 month ago

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.

nicmart-dev commented 1 month ago

Prerequisite: #15

  1. Install Google Auth Library In your React project, install the google-auth-library and other necessary dependencies:

npm install google-auth-library @react-oauth/google

  1. Configure OAuth in React Set up Google OAuth in your React application. Use the @react-oauth/google package to handle authentication.
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;
nicmart-dev commented 1 month ago

Design doc: https://github.com/nicmart-dev/linguistnow/wiki/Google-Authentication