Skip to content

Instantly share code, notes, and snippets.

@mikehibm
Created June 13, 2020 23:49
Show Gist options
  • Save mikehibm/3aa1df5753beac5bee4ce1f39e01b4fc to your computer and use it in GitHub Desktop.
Save mikehibm/3aa1df5753beac5bee4ce1f39e01b4fc to your computer and use it in GitHub Desktop.
/* eslint-disable no-undef */
const config = {
clientId: process.env.REACT_APP_CLIENTID,
scope: 'profile email',
};
export function init(onInit) {
if (!gapi) {
throw new Error('Google API SDK is not loaded.');
}
gapi.load('client:auth2', async () => {
try {
await gapi.client.init(config);
const user = gapi.auth2.getAuthInstance().currentUser.get();
onInit(user);
} catch (error) {
onInit(null, error);
}
});
}
export async function signIn() {
return gapi.auth2.getAuthInstance().signIn();
}
export async function signOut() {
return gapi.auth2.getAuthInstance().signOut();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment