An Open Source JavaScript wrapper for Firebase's native and third-party authentication.
#####HTML
<script src="https://rawgit.com/FireAuth/FireAuth/master/FireAuth-0.0.1.js"></script>
or
<script src="path/to/FireAuth-0.0.1.js"></script>
#####JS ######Example
var ref = new Firebase("https://bu1691k7rvt.firebaseio-demo.com/");
ref.createUserWithEmail("[email protected]", "thisismypassword", function(error, userData){ //creates a user
if(error){
console.log("Account creation failed: " + error); //user creation unsuccessful
} else{
console.log("Account creation succeeded!"); //user creation successful
ref.child('user').child(userData.uid).set({ //creates a child with the users firebase simplelogin
user: true, //ID and stores the user's information
username: username,
email: email,
likes: { //NOTE: It is highly reccomended that that user's password is not stored
1: "dogs", //in the JSON tree as Firebase does this already
2: "pizza"
}
});
}
});
ref.loginWithEmail("[email protected]", "thisismypassword", true, function(authData){ //logs in a user
var userRef = ref.child('user').child(authData.uid); //access the users information from JSON tree
userRef.once('value', function(snapshot){
console.log(snapshot.val().username.val); //prints out the users email which was stored in the JSON tree
});
});
ref.logout(); //logs user out
#####Node Module
######Installation
npm install fireauth
######NodeJS Usage
var Firebase = require('firebase'); //the class firebase must be capitalized as shown.
var fireauth = require('fireauth');
var ref = new Firebase("https://bu1691k7rvt.firebaseio-demo.com/");
//Now you have access to all of the JS functions.
Kind: global function
Param | Type | Description |
---|---|---|
foundToken | function | A function with the parameter authData that will get called if a token. |
noToken | function | A function with the parameter error that will get called if no token is found. |
Example
ref.checkForAvailableToken(function(authData){
doStuffWith(authData);
},function(error){
doStuffWith(error);
});
Creates a new Firebase user with Email and Password Authentication.
Kind: global function
Param | Type | Description |
---|---|---|
string | The user's email | |
password | string | The user's password |
callback | function | Optional callback function with parameter userData. (Called upon successful account creation) |
Example
ref.createUserWithEmail("[email protected]", "correcthorsebatterystaple", function(userData){
// The user creation was successful
doStuffWith(userData);
})
Logs in a Firebase user with Email and Password Authentication.
Kind: global function
Param | Type | Description |
---|---|---|
string | The user's email | |
password | string | The user's password |
token | boolean | True to create an auth token, false to not create one. |
callback | function | Optional callback function with parameter authData. (Called upon successful login) |
Example
ref.loginWithEmail("[email protected]", "correcthorsebatterystaple", false, function(authData){
// The authentication was successful.
doStuffWith(authData);
})
Changes a Firebase user's password.
Kind: global function
Param | Type | Description |
---|---|---|
string | The user's email | |
oldPassword | string | The user's original password |
newPassword | string | The user's new password |
callback | function | Optional callback function. (Called upon successful password change) |
Example
ref.changeUserPassword("[email protected]", "correcthorsebatterystaple", "youwillneverguessthis", function(){
// Password has been changed - handle anything else here.
})
Changes a Firebase user's email.
Kind: global function
Param | Type | Description |
---|---|---|
oldEmail | string | The user's original email |
newEmail | string | The user's new email |
password | string | The user's password |
callback | function | Optional callback function. (Called upon successful email change) |
Example
ref.changeUserEmail("[email protected]", "[email protected]", "correcthorsebatterystaple", function(){
// Email has been changed - handle anything else here.
})
Sends a reset password email to the user.
Kind: global function
Param | Type | Description |
---|---|---|
string | The user's email | |
callback | function | Optional callback function. (Called once reset email is sent) |
Example
ref.resetUserPassword("[email protected]", function(){
// Email has been sent - handle anything else here.
})
Deletes a Firebase user with Email and Password Authentication.
Kind: global function
Param | Type | Description |
---|---|---|
string | The user's email | |
password | string | The user's password |
callback | function | Optional callback function. (Called upon successful account deletion) |
Example
ref.deleteUserWithEmail("[email protected]", "correcthorsebatterystaple", function(){
// Successfully deleted user within Firebase - Handle anything else here.
})
Logs in a Firebase user with Facebook Authentication. Make sure your application is configured as a Facebook App.
Kind: global function
Param | Type | Description |
---|---|---|
options.redirect | boolean | Whether the webpage should redirect the current page. If false or not defined the webpage will just open a popup to Twitter. |
options.token | boolean | True to create an auth token, false or undefined to not create one. |
options.sessionTime | string | If not specified - or set to default - sessions are persisted for as long as you have configured in the Login & Auth tab of your App Dashboard. To limit persistence to the lifetime of the current window, set this to sessionOnly. A value of none will not persist authentication data at all and will end authentication as soon as the page is closed. |
options.permissions | string | A set of permissions your application may want to access from the user's Github account. Certain permissions will have to be approved by the user and Github. Each of these permissions can be accessed through the callback. Click here to view some of the permissions that can be access from Github. |
callback | function | Optional callback function with parameters error and authData that will not get called if redirect is true. (Called upon successful or unsuccessful login) [NOTE: Alternatively, the authData from any login method can be accessed universally from the "authChangeListener" function] |
Example
var settings = {
token: false,
redirect: true,
sessionTime: "none",
permissions: "email, user_likes"
};
ref.loginWithFacebook(settings, function(error, authData){
// The authentication was successful and opened within a popup.
if(error){
debugError(error);
}else{
doStuffWith(authData);
}
});
Logs in a Firebase user with GitHub Authentication. Make sure your application is configured as a GitHub App.
Kind: global function
Param | Type | Description |
---|---|---|
options.redirect | boolean | Whether the webpage should redirect the current page. If false or not defined the webpage will just open a popup to Twitter. |
options.token | boolean | True to create an auth token, false or undefined to not create one. |
options.sessionTime | string | If not specified - or set to default - sessions are persisted for as long as you have configured in the Login & Auth tab of your App Dashboard. To limit persistence to the lifetime of the current window, set this to sessionOnly. A value of none will not persist authentication data at all and will end authentication as soon as the page is closed. |
options.permissions | string | A set of permissions your application may want to access from the user's Github account. Certain permissions will have to be approved by the user and Github. Each of these permissions can be accessed through the callback. Click here to view some of the permissions that can be access from Github. |
callback | function | Optional callback function with parameters error and authData that will not get called if redirect is true. (Called upon successful or unsuccessful login) [NOTE: Alternatively, the authData from any login method can be accessed universally from the "authChangeListener" function] |
Example
var settings = {
token: true,
redirect: false,
sessionTime: "default",
permissions: "user, notifications, read:org"
};
ref.loginWithGithub(settings, function(error, authData){
// The authentication was successful and opened within a popup.
if(error){
debugError(error);
}else{
doStuffWith(authData);
}
});
Logs in a Firebase user with Google Authentication. Make sure your application is configured as a Google App.
Kind: global function
Param | Type | Description |
---|---|---|
options.redirect | boolean | Whether the webpage should redirect the current page. If false or not defined the webpage will just open a popup to Twitter. |
options.token | boolean | True to create an auth token, false or undefined to not create one. |
options.sessionTime | string | If not specified - or set to default - sessions are persisted for as long as you have configured in the Login & Auth tab of your App Dashboard. To limit persistence to the lifetime of the current window, set this to sessionOnly. A value of none will not persist authentication data at all and will end authentication as soon as the page is closed. |
options.permissions | string | A set of permissions your application may want to access from the user's Github account. Certain permissions will have to be approved by the user and Github. Each of these permissions can be accessed through the callback. Click here to view some of the permissions that can be access from Github. |
callback | function | Optional callback function with parameters error and authData that will not get called if redirect is true. (Called upon successful or unsuccessful login) [NOTE: Alternatively, the authData from any login method can be accessed universally from the "authChangeListener" function] |
Example
var settings = {
token: true,
redirect: false,
sessionTime: "none",
permissions: "profile, openid"
};
ref.loginWithGoogle(settings, function(error, authData){
// The authentication was successful and opened within a popup.
if(error){
debugError(error);
}else{
doStuffWith(authData);
}
});
Logs in a Firebase user with Twitter Authentication. Make sure your application is configured as a Twitter App.
Kind: global function
Param | Type | Description |
---|---|---|
options | object | Object with optional values. |
options.redirect | boolean | Whether the webpage should redirect the current page. If false or not defined the webpage will just open a popup to Twitter. |
options.token | boolean | True to create an auth token, false or undefined to not create one. |
options.sessionTime | string | If not specified - or set to default - sessions are persisted for as long as you have configured in the Login & Auth tab of your App Dashboard. To limit persistence to the lifetime of the current window, set this to sessionOnly. A value of none will not persist authentication data at all and will end authentication as soon as the page is closed. |
callback | function | Optional callback function with parameters error and authData that will not get called if redirect is true. (Called upon successful or unsuccessful login) [NOTE: Alternatively, the authData from any login method can be accessed universally from the "authChangeListener" function] |
Example
var settings = {
redirect: true,
token: false,
sessionTime: "default"
};
ref.loginWithTwitter(settings, function(error, authData){
// The authentication was successful and opened within a popup.
if(error){
debugError(error);
}else{
doStuffWith(authData);
}
});
Logs out a user and removes authentication token.
Kind: global function Example
ref.logout();
Event handler checks any changes in user authentication. Can also be used as an alternative to callbacks from other login functions.
Kind: global function
Param | Type | Description |
---|---|---|
onLogin | function | A function with parameter authData that will get called if the user becomes authenticated or is already logged in. |
onLogout | function | A function with parameter authData that will get called if the user becomes unauthenticated or is already logged out. |
Example
ref.authChangeListener(function(authData){
//The user has logged in
doStuffWith(authData);
}, function(authData){
//The user has logged out
doStuffWith(authData);
});
Sets the token id or name.
Kind: global function
Param | Type | Description |
---|---|---|
newTokenName | string | the new name of your token. |
Example
ref.setTokenName("myTokenForMyFirstWebApp");