Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't use custom login button #1

Closed
koraykavruk opened this issue May 11, 2022 · 1 comment
Closed

I can't use custom login button #1

koraykavruk opened this issue May 11, 2022 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@koraykavruk
Copy link

I couldn't use it with custom button. It wants auth provider, but useGoogleLogin cannot be used in auth provider. Can you help me? It would be nice if the client id could be sent as options in useGoogleLogin.

@MomenSherif
Copy link
Owner

MomenSherif commented May 11, 2022

Hello @koraykavruk,

Thank you for being the first one to open an issue :D,

We need to add GoogleOAuthProvider component (step number 3 in how-to-use) and pass clientId as a props, which is normal context provider similar to store provider of redux as an example.

you can add provider any where you like to add it is just context provider which will provide all values to its descendent

if you provided in App component for example

export default function App() {
  return (
    <GoogleOAuthProvider clientId="xxxx">
      <div>
        <h1>@react-oauth/google</h1>
        <LoginPage />
      </div>
    </GoogleOAuthProvider>
  );
}

function LoginPage() {
  const login = useGoogleLogin({
    onSuccess: tokenResponse => {
      console.log(tokenResponse);
    },
  });

  return (
    <div>
      <button onClick={() => login()}>Login with google✌</button>
    </div>
  );
}

useLogin is used in component LoginPage, which is rendered inside GoogleOAuthProvider, it can be at any level of react components tree

if you provided around in react entry file. for example index.js in create-react-app

ReactDOM.createRoot(document.getElementById('root')).render(
    <React.StrictMode>
      <GoogleOAuthProvider clientId='xxxx'>
       <App />
      </GoogleOAuthProvider>
    </React.StrictMode>,
);

and you can use the hook inside you component for example because you are rendered inside the provider.

unfortunately changing useGoogleLogin api to have clientId, will require changes in the hole package which will increase its size and I consider the size to be small as possible (check bundlephobia).

and the effort of adding the <GoogleOAuthProvider /> is a small step.

@MomenSherif MomenSherif self-assigned this May 13, 2022
@MomenSherif MomenSherif added the question Further information is requested label May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants