Created
June 13, 2020 23:49
-
-
Save mikehibm/3aa1df5753beac5bee4ce1f39e01b4fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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