Created
August 11, 2016 06:50
-
-
Save jaxxreal/bdff47c400ca34b528b8c185aedb9e0b to your computer and use it in GitHub Desktop.
Social login/sign up pattern
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
const regObj = { | |
accountName: "", | |
provider: "Facebook", | |
externalAccessToken: "", | |
}; | |
FB.login((response) => { | |
console.log("statusChangeCallback"); | |
console.log(response); | |
regObj.externalAccessToken = response.authResponse.accessToken; | |
if (response.status === "connected") { | |
// Logged into your app and Facebook. | |
fetchuserData(); | |
} else if (response.status === "not_authorized") { | |
dispatch(registerExternalFacebook()); | |
// The person is logged into Facebook, but not your app. | |
} else { | |
// The person is not logged into Facebook, so we're not sure if | |
// they are logged into this app or not. | |
dispatch(registerExternalFacebook()); | |
} | |
}, { scope: "public_profile,email" }); | |
function fetchuserData() { | |
FB.api("/me?fields=email,name", (response) => { | |
regObj.accountName = response.email; | |
}); | |
} |
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
gapi.auth2 | |
.getAuthInstance() | |
.signIn() | |
.then((googleUser) => { | |
const profile = googleUser.getBasicProfile(); | |
const regObj = { | |
accountName: profile.getEmail(), | |
provider: "Google", | |
externalAccessToken: googleUser.getAuthResponse().access_token, | |
}; | |
}); |
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
window["gapiAsyncInit"] = () => { | |
gapi.load("auth2", () => gapi.auth2.init({ | |
client_id: GOOGLE_CLIENT_ID, | |
fetch_basic_profile: true, | |
scope: GOOGLE_SCOPE | |
})); | |
}; | |
window["fbAsyncInit"] = () => { | |
FB.init({ | |
appId: FACEBOOK_APP_ID, | |
cookie: true, | |
version: "v2.5" | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment