Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
gapi-oauth-react-hooks
Advanced tools
Uh yea... That's a mouthfull.
I needed SSO for google users and wasn't quite satisfied with what I found in the react eco system. Perhaps this will be useful for someone else, so here we go.
First of, this will only work for react > 16.8 since it uses hooks. To install, use either yarn or npm:
yarn add gapi-oauth-react-hooks
npm i gapi-oauth-react-hooks
It's best to setup the config early, perhaps in the index or app file:
import { GapiConfig } from "gapi-oauth-react-hooks";
// pulling from .env here
GapiConfig.setup(
process.env.GOOGLE_AUTH_CLIENTID,
process.env.GOOGLE_AUTH_SCOPE,
process.env.GOOGLE_AUTH_REDIRECTURI
);
ReactDOM.render(<Login />, document.getElementById("root"));
Now, let's use the hook in the Login component:
import { useGapiLogin, GapiState } from "gapi-oauth-react-hooks";
export const Login: React.FC = () => {
const [state, user, handleSignIn, handleSignOut] = useGapiLogin();
if (state === GapiState.Loading)
return <div>Well, gapi is being loaded...</div>;
if (state === GapiState.SignedIn)
return (
<>
<div>user {JSON.stringify(user)}</div>
<SimpleButton onClick={handleSignOut} text="Logout" />
</>
);
return <SimpleButton onClick={handleSignIn} text="Login" />;
};
This package exposes three entities:
A static class to hold gapi configuration
This class contains a config function that takes three parameters:
An interface defining the states Gapi can be at
This interface has the following members:
A react hook to handle signin and signout using gapi auth2
This hook returns:
The package exposes its own declaration files; you won't need to install an @types/* if you use typescript.
FAQs
Some hooks for SSO using Google sign in
We found that gapi-oauth-react-hooks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.