Last active
September 16, 2016 12:39
-
-
Save janis-kra/746738fe37fa071c4b7216dee51b6666 to your computer and use it in GitHub Desktop.
Extending Oracle JET with Google Sign-In — how not to do it either
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
<div id="google-signin-button" class="g-signin2" data-onsuccess="onSignIn">Google Singin is loading</div> |
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
// in one of your ViewModels | |
self.signIn = function (googleUser) { | |
var profile = googleUser.getBasicProfile(); | |
var token = googleUser.getAuthResponse().id_token; | |
var name = profile.getName(); | |
// safe the user data to your ViewModel's variables: | |
self.username(name); | |
self.token(token); | |
// log into your backend webservice: | |
login(token).then(updateUiOnLogin); | |
alert('Welcome, ' + self.username() + '!'); | |
}; | |
window.onSignIn = self.signIn; // must be known globally for the google signin button to work |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This approach allows you to store the users data in your ViewModel. However, there are still three problems left here:
script
tag in the HTML header is at the very least a code smell here.