Last active
September 28, 2019 13:47
-
-
Save jackrobertscott/226b2676048115c7ff4be92b9daa85ae 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
/** | |
* Helper function to get the library with access to the google plus api. | |
*/ | |
function getGooglePlusApi(auth) { | |
return google.plus({ version: 'v1', auth }); | |
} | |
/** | |
* Extract the email and id of the google account from the "code" parameter. | |
*/ | |
function getGoogleAccountFromCode(code) { | |
// get the auth "tokens" from the request | |
const data = await auth.getToken(code); | |
const tokens = data.tokens; | |
// add the tokens to the google api so we have access to the account | |
const auth = createConnection(); | |
auth.setCredentials(tokens); | |
// connect to google plus - need this to get the user's email | |
const plus = getGooglePlusApi(auth); | |
const me = await plus.people.get({ userId: 'me' }); | |
// get the google id and email | |
const userGoogleId = me.data.id; | |
const userGoogleEmail = me.data.emails && me.data.emails.length && me.data.emails[0].value; | |
// return so we can login or sign up the user | |
return { | |
id: userGoogleId, | |
email: userGoogleEmail, | |
tokens: tokens, // you can save these to the user if you ever want to get their details without making them log in again | |
}; | |
} |
I'm getting same error as stevan and can't get to find what is going wrong
await is a reserved word
Hey Jack - When this code executes i get the error "ReferenceError: auth is not defined" - where is auth meant to have been defined?
const auth = createConnection();
put this before line number 14
Hi I am getting error on the below line
const data = await auth.getToken(code);
await can not be used... how to fix it?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Jack - When this code executes i get the error "ReferenceError: auth is not defined" - where is auth meant to have been defined?