Skip to content

Commit

Permalink
support va-cordova-oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
Saneyan committed Aug 15, 2016
1 parent f6c1b84 commit ae55540
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
/.idea
/bower_components
14 changes: 14 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "va-cordova-oauth",
"version": "0.0.1",
"description": "Useful web component for user authentication with Firebase.",
"license": "MIT",
"dependencies": {
"promise-polyfill": "polymerlabs/promise-polyfill#^1.0.0",
"polymer": "polymer/polymer#^1.6.0",
"va-cordova-oauth": "via-at/va-cordova-oauth"
},
"devDependencies": {
"web-component-tester": "^4.0.0"
}
}
68 changes: 46 additions & 22 deletions va-auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<firebase-auth id="auth"></firebase-auth>

<va-auth-dialog id="dialog"></va-auth-dialog>

<va-cordova-oauth id="cordovaAuth"></va-cordova-oauth>

</template>

Expand Down Expand Up @@ -36,35 +38,57 @@

_signInWithEmail: function (e) {
var promise = this.$.auth.signInWithEmailAndPassword(e.detail.email, e.detail.password);

promise.then(function () {
this.$.dialog.close();
this.fire('done');
}.bind(this), function () {
this.$.dialog.failSignIn();
this.fire('error');
}.bind(this));
promise.then(this._done.bind(this), this._failSignIn.bind(this));
},

_signUpWithEmail: function (e) {
var promise = this.$.auth.createUserWithEmailAndPassword(e.detail.email, e.detail.password);

promise.then(function () {
this.$.dialog.close();
this.fire('done');
}.bind(this), function () {
this.$.dialog.failSignUp();
this.fire('error');
}.bind(this));
promise.then(this._done.bind(this), this._failSignUp.bind(this));
},

_auth: function (e) {
var promise = this.$.auth.signInWithPopup(e.detail.provider);

promise.then(function () {
this.$.dialog.close();
this.fire('done');
}.bind(this));
var provider = e.detail.provider;

if (cordova) {
var url = this.resolveUrl('../va-cordova-oauth/va-cordova-oauth.html', null, null, true);

this.importHref(url, function () {
this.$.cordovaAuth.signIn(provider).then(function () {
var credential;

switch (provider) {
case 'google':
credential = firebase.auth.GoogleAuthProvider.credential(arguments[0], null);
break;
case 'facebook':
credential = firebase.auth.FacebookAuthProvider.credential(arguments[0]);
break;
case 'twitter':
credential = firebase.auth.TwitterAuthProvider.credential(arguments[0], arguments[1]);
break;
}

this.$.auth.signInWithCredential(credential).then(this._done.bind(this));
}.bind(this));
}.bind(this));
} else {
this.$.auth.signInWithPopup(provider).then(this._done.bind(this));
}
},

_done: function () {
this.$.dialog.close();
this.fire('done');
},

_failSignIn: function () {
this.$.dialog.failSignIn();
this.fire('error');
},

_failSignUp: function () {
this.$.dialog.failSignUp();
this.fire('error');
}

});
Expand Down

0 comments on commit ae55540

Please sign in to comment.