I am using vuejs 2 and am having problems using the google auth icon.
I successfully installed and got the exit functions and user profile functions using vue:
export default {
data() {
return {
user: null
};
},
methods: {
getUserProfile() {
const profile = gapi.auth2.currentUser.get().getBasicProfile();
console.log(profile.getIdToken());
},
signOut() {
const auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('user signed out');
});
}
},
};
My main problem here is the function onSignIn(googleUser)from
<div class="g-signin2" data-onsuccess="onSignIn"></div>
data-onsuccess="onSignIn"looking for js function outside of vue instance. I tried to add a function onSignIn(googleUser)to my HTML file, for example:
<script>
function onSignIn(googleUser) {
const auth2 = gapi.auth2.init();
if (auth2.isSignedIn.get()) {
const profile = auth2.currentUser.get().getBasicProfile();
console.log(profile.getName());
console.log(googleUser.getAuthResponse().id_token);
console.log(googleUser.getAuthResponse().uid);
console.log(auth2.currentUser.get().getId());
}
}
</script>
This works as expected, but I wanted to know if I could add this to my vue file instead of my own javascript method, since inside this function I will call other vue methods.
Or is there a way I could add a function onSignIn(googleUser)to vue and then call it when Google Auth ends?