Skip to content

Instantly share code, notes, and snippets.

@janis-kra
Last active September 16, 2016 12:39
Show Gist options
  • Save janis-kra/746738fe37fa071c4b7216dee51b6666 to your computer and use it in GitHub Desktop.
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
<div id="google-signin-button" class="g-signin2" data-onsuccess="onSignIn">Google Singin is loading</div>
// 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
@janis-kra
Copy link
Author

This approach allows you to store the users data in your ViewModel. However, there are still three problems left here:

  1. The onSignIn function is leaked to the global window object once again, and it is kind of an ugly workaround.
  2. In JET, you normally use Requirejs and Bower to manage and load your dependencies (such as Knockout, Hammer etc.). Loading an additional external dependency via a script tag in the HTML header is at the very least a code smell here.
  3. The signin button does not adhere to the Alta UI look & feel (which may or may not be a problem for you and your application).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment