Skip to content

Instantly share code, notes, and snippets.

@jaxxreal
Created August 11, 2016 06:50
Show Gist options
  • Save jaxxreal/bdff47c400ca34b528b8c185aedb9e0b to your computer and use it in GitHub Desktop.
Save jaxxreal/bdff47c400ca34b528b8c185aedb9e0b to your computer and use it in GitHub Desktop.
Social login/sign up pattern
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;
});
}
gapi.auth2
.getAuthInstance()
.signIn()
.then((googleUser) => {
const profile = googleUser.getBasicProfile();
const regObj = {
accountName: profile.getEmail(),
provider: "Google",
externalAccessToken: googleUser.getAuthResponse().access_token,
};
});
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