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
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 :rocket:
The package exposes its own declaration files; you won't need to install any @types/* if you use typescript.
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 main hook in our Login component:
import { useGoogleAuth, UserProfile } from "gapi-oauth-react-hooks";
export const Login = () => {
const auth = useGoogleAuth();
const display = {
Errored: <>Oh no!</>,
Loading: <>Loading ...</>,
NotSignedIn: <button onClick={auth.onSignIn} >Login</button>,
SignedIn: <SignedIn {...auth} />
};
return <>{display[auth.state]}</>;
};
interface SignedInProps {
onSignOut: () => Promise<void>;
signedUser?: UserProfile;
authResponse?: gapi.auth2.AuthResponse;
}
const SignedIn: React.FC<SignedInProps> = ({ onSignOut, signedUser, authResponse }) => (
<>
<div>user {JSON.stringify(signedUser)}</div>
<div>auth response {JSON.stringify(authResponse)}</div>
<button onClick={onSignOut} >Logout</button>
</>
);
This package exposes two functions as well as two types:
This type can have the following values:
This class contains a config function that takes three parameters:
import { GapiConfig } from 'gapi-oauth-react-hooks';
GapiConfig.setup(clientId, scope, redirectUri);
This hook returns an object containing:
import { useGoogleAuth } from 'gapi-oauth-react-hooks';
const { state, signedUser, authResponse, onSignIn, onSignOut } =
useGoogleAuth();
FAQs
Some hooks for SSO using Google sign in
The npm package gapi-oauth-react-hooks receives a total of 3 weekly downloads. As such, gapi-oauth-react-hooks popularity was classified as not popular.
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.