mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #1888 from wilkerlucio/firebase_upgrade
added interfaces for firebase simple login
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
/// <reference path="./firebase-simplelogin.d.ts" />
|
||||
|
||||
var chatRef: Firebase = new Firebase('https://<YOUR-FIREBASE>.firebaseio.com');
|
||||
var auth: FirebaseSimpleLogin = new FirebaseSimpleLogin(chatRef, function(error, user) {
|
||||
if (error) {
|
||||
// an error occurred while attempting login
|
||||
switch(error.code) {
|
||||
case 'INVALID_EMAIL':
|
||||
case 'INVALID_PASSWORD':
|
||||
default:
|
||||
}
|
||||
} else if (user) {
|
||||
// user authenticated with Firebase
|
||||
console.log('User ID: ' + user.id + ', Provider: ' + user.provider);
|
||||
} else {
|
||||
// user is logged out
|
||||
}
|
||||
});
|
||||
|
||||
var email = 'my@email.com';
|
||||
var password = 'secret';
|
||||
var oldPassword = 'secret';
|
||||
var newPassword = 'secret';
|
||||
|
||||
auth.login('password', {
|
||||
email: '<email@domain.com>',
|
||||
password: '<password>',
|
||||
rememberMe: true
|
||||
});
|
||||
|
||||
auth.login('facebook', {
|
||||
rememberMe: true,
|
||||
scope: 'email,user_likes'
|
||||
});
|
||||
|
||||
auth.login('github', {
|
||||
rememberMe: true,
|
||||
scope: 'user,gist'
|
||||
});
|
||||
|
||||
auth.login('google', {
|
||||
rememberMe: true,
|
||||
scope: 'https://www.googleapis.com/auth/plus.login'
|
||||
});
|
||||
|
||||
auth.login('persona', {
|
||||
rememberMe: true
|
||||
});
|
||||
|
||||
auth.login('twitter', {
|
||||
rememberMe: true
|
||||
});
|
||||
|
||||
auth.login('anonymous');
|
||||
|
||||
auth.createUser(email, password, function(error, user) {
|
||||
if (!error) {
|
||||
console.log('User Id: ' + user.id + ', Email: ' + user.email);
|
||||
}
|
||||
});
|
||||
|
||||
auth.createUser(email, password);
|
||||
|
||||
auth.changePassword(email, oldPassword, newPassword, function(error, success) {
|
||||
if (!error) {
|
||||
console.log('Password changed successfully');
|
||||
}
|
||||
});
|
||||
|
||||
auth.changePassword(email, oldPassword, newPassword);
|
||||
|
||||
auth.sendPasswordResetEmail(email, function(error, success) {
|
||||
if (!error) {
|
||||
console.log('Password reset email sent successfully');
|
||||
}
|
||||
});
|
||||
|
||||
auth.sendPasswordResetEmail(email);
|
||||
|
||||
auth.removeUser(email, password, function(error, success) {
|
||||
if (!error) {
|
||||
console.log('User deleted successfully');
|
||||
}
|
||||
});
|
||||
|
||||
auth.removeUser(email, password);
|
||||
Vendored
+94
@@ -0,0 +1,94 @@
|
||||
// Type definitions for Firebase Simple Login
|
||||
// Project: https://www.firebase.com/docs/security/simple-login-overview.html
|
||||
// Definitions by: Wilker Lucio <http://github.com/wilkerlucio>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="./firebase.d.ts" />
|
||||
|
||||
interface IFirebaseSimpleLoginError {
|
||||
code: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
interface IFirebaseSimpleLoginOptions {
|
||||
// general options
|
||||
debug?: boolean
|
||||
rememberMe?: boolean
|
||||
|
||||
// email
|
||||
email?: string
|
||||
password?: string
|
||||
|
||||
// facebook / github / google / twitter
|
||||
preferRedirect?: boolean
|
||||
|
||||
// facebook / github / google
|
||||
scope?: string
|
||||
|
||||
// facebook
|
||||
access_token?: string
|
||||
|
||||
// twitter
|
||||
oauth_token?: string
|
||||
|
||||
// persona
|
||||
backgroundColor?: string
|
||||
privacyPolicy?: string
|
||||
siteLogo?: string
|
||||
siteName?: string
|
||||
termsOfService?: string
|
||||
}
|
||||
|
||||
interface IFirebaseSimpleLoginUser {
|
||||
// general data
|
||||
firebaseAuthToken: string;
|
||||
id: string;
|
||||
provider: string;
|
||||
uid: string;
|
||||
|
||||
// email / persona
|
||||
md5_hash?: string;
|
||||
|
||||
// email
|
||||
email?: string;
|
||||
|
||||
// facebook / github / google / twitter
|
||||
accessToken?: string
|
||||
displayName?: string
|
||||
thirdPartyUserData?: Object
|
||||
|
||||
// github / twitter
|
||||
username?: string
|
||||
|
||||
// twitter
|
||||
accessTokenSecret?: string
|
||||
}
|
||||
|
||||
declare class FirebaseSimpleLogin {
|
||||
email: string;
|
||||
id: string;
|
||||
provider: string;
|
||||
uid: string;
|
||||
username: string;
|
||||
|
||||
constructor(firebase: Firebase, callback: (err: IFirebaseSimpleLoginError, user: IFirebaseSimpleLoginUser) => any);
|
||||
|
||||
login(loginType: string, options?: IFirebaseSimpleLoginOptions): void;
|
||||
logout(): void;
|
||||
|
||||
createUser(email: string,
|
||||
password: string,
|
||||
callback?: (err: IFirebaseSimpleLoginError, user: IFirebaseSimpleLoginUser) => any): void;
|
||||
|
||||
changePassword(email: string,
|
||||
oldPassword: string,
|
||||
newPassword: string,
|
||||
callback?: (err: IFirebaseSimpleLoginError, success: boolean) => any): void;
|
||||
|
||||
sendPasswordResetEmail(email: string,
|
||||
callback?: (err: IFirebaseSimpleLoginError, success: boolean) => any): void;
|
||||
|
||||
removeUser(email: string,
|
||||
password: string,
|
||||
callback?: (err: IFirebaseSimpleLoginError, success: boolean) => any): void;
|
||||
}
|
||||
Reference in New Issue
Block a user