Skip to content

Commit

Permalink
'minor-fixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
loitranduc committed Mar 14, 2019
1 parent 74f56c7 commit aa2fdaf
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 5 deletions.
63 changes: 61 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,65 @@ import "./plugins/allauth";
* In `src/plugins/allauth.js` add these lines:
```
import VueAllAuth from "vue-all-auth";
Vue.use(VueAllAuth, { client_id: "YOUR_CLIENT_ID.apps.googleusercontent.com" });
Vue.allAuth().init();
Vue.use(VueAllAuth, {
google: {
// keys for google
client_id: "YOUR_GG_APP_ID.apps.googleusercontent.com",
scope: "profile email",
},
facebook: {
// keys for fb
appId: "YOUR_FB_APP_ID",
cookie: true,
xfbml: true,
version: "v3.2",
},
twitter: {
// keys for twitter
},
github: {
// keys for github
}
});
Vue.allAuth().google().init();
Vue.allAuth().facebook().init();
```
* Inside Vue.js component file:
```
# Template part
<!-- Google login button -->
<b-form-group>
<b-button type="submit" variant="danger" @click="ggSignIn" style="min-width: 15rem;">
<font-awesome-icon :icon="['fab', 'google']" class="mr-1"/>
Continue with Google
</b-button>
</b-form-group>
```
Javascript part:
```
import Vue from "vue";
export default {
name: "SocialLoginForm",
methods: {
ggSignIn: function (event) {
// Prevent default action
event.preventDefault()
// console.log("Begin google authentication!");
Vue.allAuth().google().init()
// console.log("This is this before calling allAuth(): ");
let that = this
Vue.allAuth().google().signIn(function (googleUser) {
// console.log("This is googleUser in SocialLoginForm: "+googleUser);
Vue.allAuth().google().printInfo() //just to check what you received
// console.log("This is this in SocialLoginForm: ");
// console.log(this); //--> at this time, this is undefined, that will be a Vue instance
that.$router.push("/")
}, function (error) {
console.log("Something went wrong!");
console.log(error);
})
},
}
}
```
34 changes: 31 additions & 3 deletions facebookAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ let facebookAuth = {
return new Promise(function(resolve, reject){
// do something here
let fbClientScript = document.createElement("script")
fbClientScript.setAttribute("src", "https://connect.facebook.net/en_US/sdk.js")
// fbClientScript.setAttribute("src", "https://connect.facebook.net/en_US/sdk.js")
fbClientScript.setAttribute("src", "https://connect.facebook.net/pl_PL/all.js")
// Not handle connect timeout case yet
// Append the script onto the head element
// document.head.appendChild(ggClientScript)
Expand Down Expand Up @@ -55,9 +56,36 @@ let facebookAuth = {
}
});
},
fbSignIn: function(){
fbSignIn: function(successCallback, errorCallback){
// first check current status of user
// If not connected-> do the login
// More about promise: https://ehkoo.com/bai-viet/tat-tan-tat-ve-promise-va-async-await
// Basics: https://viblo.asia/p/object-trong-javascript-nhung-dieu-can-biet-V3m5W2JWlO7
return new Promise(function(resolve, reject){
// Async here
FB.getLoginStatus(function(response){
if (response.status === "connected"){
// connected - Người đó đăng nhập Facebook và đã đăng nhập ứng dụng của bạn.
console.log("Already signed in and connected.")
console.log(response)
// Ngược lại, dùng `resolve()` để trả dữ liệu về cho `.then()`
resolve(response)
} else {
// then not_authorized or unknown
FB.login(function(response){
if (response.status === "connected"){
// connected - Người đó đăng nhập Facebook và đã đăng nhập ứng dụng của bạn.
console.log("Signed in and connected.")
console.log(response)
resolve(response)
} else {
console.log("Something went wrong while logging in"+response.status)
console.log(response)
reject(response)
}
}, {scope: 'public_profile,email'})
}
})
})
}
}

Expand Down

0 comments on commit aa2fdaf

Please sign in to comment.