Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 85 additions & 19 deletions firebase-auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@

Example Usage:
```html
<firebase-app auth-domain="polymerfire-test.firebaseapp.com"
database-url="https://polymerfire-test.firebaseio.com/"
api-key="AIzaSyDTP-eiQezleFsV2WddFBAhF_WEzx_8v_g">
<firebase-app
auth-domain="polymerfire-test.firebaseapp.com"
database-url="https://polymerfire-test.firebaseio.com"
api-key="AIzaSyDTP-eiQezleFsV2WddFBAhF_WEzx_8v_g">
</firebase-app>
<firebase-auth id="auth" user="{{user}}" provider="google" on-error="handleError">

<firebase-auth
id="auth"
user="{{user}}"
provider="google"
on-error="handleError">
</firebase-auth>
```

Expand All @@ -35,8 +41,8 @@

```javascript
this.$.auth.signInWithPopup()
.then(function(response) {// optionally handle a successful login})
.catch(function(error) {// unsuccessful authentication response here});
.then(function(response) {// optionally handle a successful login})
.catch(function(error) {// unsuccessful authentication response here});
```

This popup sign-in will then attempt to sign in using Google as an OAuth
Expand Down Expand Up @@ -130,7 +136,45 @@
notify: true,
readOnly: true,
reflectToAttribute: true
}
},

/**
* Email address corresponding to the user account. This property
* can remain undefined when specifying a email in the email function calls
* (i.e. `signInWithEmailAndPassword`, `createUserWithEmailAndPassword` and `sendPasswordResetEmail`).
*/
email: {
type: String,
notify: true
},

/**
* Password corresponding to the user account. This property
* can remain undefined when specifying a password in the email function calls
* (i.e. `signInWithEmailAndPassword` and `createUserWithEmailAndPassword`).
*/
password: {
type: String,
notify: true
},

/**
* JSON Web Token. This property can remain undefined when
* specifying a token in the `signInWithCustomToken` function.
*/
token: {
type: String,
notify: true
},

/**
* OAuth id_token. This property can remain undefined when
* specifying a credential in the `signInWithCredential` function.
*/
credential: {
type: String,
notify: true
},

},

Expand All @@ -143,31 +187,36 @@
if (!this.auth) {
return Promise.reject('No app configured for firebase-auth!');
}

return this._handleSignIn(this.auth.signInAnonymously());
},

/**
* Authenticates a Firebase client using a custom JSON Web Token.
*
* @param {?String} token JSON Web Token. If not specified,
* the element's `token` property value will be used.
* @return {Promise} Promise that handles success and failure.
*/
signInWithCustomToken: function(token) {
if (!this.auth) {
return Promise.reject('No app configured for firebase-auth!');
}
token = token || this.token;
return this._handleSignIn(this.auth.signInWithCustomToken(token));
},

/**
* Authenticates a Firebase client using an oauth id_token.
*
* @param {?String} credential OAuth id_token. If not specified,
* the element's `credential` property value will be used.
* @return {Promise} Promise that handles success and failure.
*/
signInWithCredential: function(credential) {
if (!this.auth) {
return Promise.reject('No app configured for firebase-auth!');
}
credential = credential || this.credential;
return this._handleSignIn(this.auth.signInWithCredential(credential));
},

Expand Down Expand Up @@ -203,32 +252,51 @@
/**
* Authenticates a Firebase client using an email / password combination.
*
* @param {!String} email Email address corresponding to the user account.
* @param {!String} password Password corresponding to the user account.
* @param {?String} email Email address corresponding to the user account.
* If not specified, the element's `email` property value will be used.
* @param {?String} password Password corresponding to the user account.
* If not specified, the element's `password` property value will be used.
* @return {Promise} Promise that handles success and failure.
*/
signInWithEmailAndPassword: function(email, password) {
if (!this.auth) {
return Promise.reject('No app configured for firebase-auth!');
}
email = email || this.email;
password = password || this.password;
return this._handleSignIn(this.auth.signInWithEmailAndPassword(email, password));
},

/**
* Creates a new user account using an email / password combination.
*
* @param {!String} email Email address corresponding to the user account.
* @param {!String} password Password corresponding to the user account.
* @param {?String} email Email address corresponding to the user account.
* If not specified, the element's `email` property value will be used.
* @param {?String} password Password corresponding to the user account.
* If not specified, the element's `password` property value will be used.
* @return {Promise} Promise that handles success and failure.
*/
createUserWithEmailAndPassword: function(email, password) {
if (!this.auth) {
return Promise.reject('No app configured for firebase-auth!');
}
email = email || this.email;
password = password || this.password;
return this._handleSignIn(this.auth.createUserWithEmailAndPassword(email, password));
},

/**
* Sends a password reset email to the given email address.
*
* @param {!String} email Email address corresponding to the user account.
* @param {?String} email Email address corresponding to the user account.
* If not specified, the element's `email` property value will be used.
* @return {Promise} Promise that handles success and failure.
*/
sendPasswordResetEmail: function(email) {
if (!this.auth) {
return Promise.reject('No app configured for firebase-auth!');
}
email = email || this.email;
return this._handleSignIn(this.auth.sendPasswordResetEmail(email));
},

Expand All @@ -241,19 +309,17 @@
if (!this.auth) {
return Promise.reject('No app configured for auth!');
}

return this.auth.signOut();
},

_attemptProviderSignIn: function(provider, method) {
provider = provider || this._providerFromName(this.provider);
if (!provider) {
return Promise.reject('Must supply a provider for popup sign in.');
}
if (!this.auth) {
return Promise.reject('No app configured for firebase-auth!');
}

provider = provider || this._providerFromName(this.provider);
if (!provider) {
return Promise.reject('Must supply a provider for popup or redirect sign in.');
}
return this._handleSignIn(method.call(this.auth, provider));
},

Expand Down