[typings][typescript] update typings for the auth module

This commit is contained in:
Daniel W 2018-01-18 17:05:44 +01:00
parent cb28c458a8
commit 2611f7c8e3
1 changed files with 140 additions and 36 deletions

176
lib/index.d.ts vendored
View File

@ -7,7 +7,7 @@ declare module "react-native-firebase" {
type AuthProvider = { type AuthProvider = {
PROVIDER_ID: string, PROVIDER_ID: string,
credential: (token: string, secret?: string) => object, credential: (token: string, secret?: string) => AuthCredential,
}; };
export default class FireBase { export default class FireBase {
@ -533,6 +533,20 @@ declare module "react-native-firebase" {
[key: string]: any; [key: string]: any;
} }
type UserInfo = {
displayName?: string,
email?: string,
phoneNumber?: string,
photoURL?: string,
providerId: string,
uid: string,
}
type UpdateProfile = {
displayName?: string,
photoURL?: string,
}
interface User { interface User {
/** /**
* The user's display name (if available). * The user's display name (if available).
@ -550,6 +564,8 @@ declare module "react-native-firebase" {
* *
*/ */
isAnonymous: boolean isAnonymous: boolean
phoneNumber: string | null
/** /**
* - The URL of the user's profile picture (if available). * - The URL of the user's profile picture (if available).
*/ */
@ -557,12 +573,12 @@ declare module "react-native-firebase" {
/** /**
* - Additional provider-specific information about the user. * - Additional provider-specific information about the user.
*/ */
providerData: any | null providerData: Array<UserInfo>
/** /**
* - The authentication provider ID for the current user. * - The authentication provider ID for the current user.
* For example, 'facebook.com', or 'google.com'. * For example, 'facebook.com', or 'google.com'.
*/ */
providerId: string | null providerId: string
/** /**
* - The user's unique ID. * - The user's unique ID.
*/ */
@ -575,18 +591,20 @@ declare module "react-native-firebase" {
/** /**
* Returns the users authentication token. * Returns the users authentication token.
*
* @param forceRefresh: boolean - default to false
*/ */
getToken(): Promise<string> getIdToken(forceRefresh: boolean?): Promise<string>
/**
* Reauthenticate the current user with credentials:
*/
reauthenticate(credential: Credential): Promise<void>
/** /**
* Link the user with a 3rd party credential provider. * Link the user with a 3rd party credential provider.
*/ */
linkWithCredential(credential: Credential): Promise<User> linkWithCredential(credential: AuthCredential): Promise<User>
/**
* Re-authenticate a user with a third-party authentication provider
*/
reauthenticateWithCredential(credential: AuthCredential): Promise<void>
/** /**
* Refreshes the current user. * Refreshes the current user.
@ -597,7 +615,11 @@ declare module "react-native-firebase" {
* Sends a verification email to a user. * Sends a verification email to a user.
* This will Promise reject is the user is anonymous. * This will Promise reject is the user is anonymous.
*/ */
sendEmailVerification(): Promise<void> sendEmailVerification(actionCodeSettings?: ActionCodeSettings): Promise<void>
toJSON(): object
unlink(providerId: string): Promise<User>
/** /**
* Updates the user's email address. * Updates the user's email address.
@ -617,16 +639,28 @@ declare module "react-native-firebase" {
* Updates a user's profile data. * Updates a user's profile data.
* Profile data should be an object of fields to update: * Profile data should be an object of fields to update:
*/ */
updateProfile(profile: Object): Promise<void> updateProfile(updates: UpdateProfile): Promise<void>
} }
/** 3rd party provider Credentials */ /** 3rd party provider Credentials */
interface Credential { type AuthCredential {
provider: string, providerId: string,
token: string, token: string,
secret: string secret: string
} }
type ActionCodeSettings = {
android: {
installApp?: boolean,
minimumVersion?: string,
packageName: string,
},
handleCodeInApp?: boolean,
iOS: {
bundleId?: string,
},
url: string,
}
interface ActionCodeInfo { interface ActionCodeInfo {
email: string, email: string,
@ -637,17 +671,55 @@ declare module "react-native-firebase" {
passwordReset: string passwordReset: string
} }
interface ConfirmationResult {
confirm(verificationCode: string): Promise<User | null>;
verificationId: string | null;
}
type PhoneAuthSnapshot = {
state: 'sent' | 'timeout' | 'verified' | 'error',
verificationId: string,
code: string | null,
error: Error | null,
};
type PhoneAuthError = {
code: string | null,
verificationId: string,
message: string | null,
stack: string | null,
};
interface PhoneAuthListener {
on(event: string,
observer: () => PhoneAuthSnapshot,
errorCb?: () => PhoneAuthError,
successCb?: () => PhoneAuthSnapshot): PhoneAuthListener;
then(fn: () => PhoneAuthSnapshot): Promise<any>
catch(fn: () => Error): Promise<any>
}
namespace auth { namespace auth {
type AuthResult = {
authenticated: boolean,
user: object | null
} | null;
interface Auth { interface Auth {
/** /**
* Returns the current Firebase authentication state. * Returns the current Firebase authentication state.
*/ */
authenticated: boolean; authResult: AuthResult | null;
/** /**
* Returns the currently signed-in user (or null). See the User class documentation for further usage. * Returns the currently signed-in user (or null). See the User class documentation for further usage.
*/ */
currentUser: User | null user: User | null
/** /**
* Gets/Sets the language for the app instance * Gets/Sets the language for the app instance
@ -659,8 +731,30 @@ declare module "react-native-firebase" {
* This method returns a unsubscribe function to stop listening to events. * This method returns a unsubscribe function to stop listening to events.
* Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use. * Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use.
*/ */
onAuthStateChanged(nextOrObserver: Object, error?: (a: RnError) => any, onAuthStateChanged(listener: Function): () => void;
completed?: () => any): () => any;
/**
* Listen for changes in id token.
* This method returns a unsubscribe function to stop listening to events.
* Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use.
*/
onIdTokenChanged(listener: Function): () => void;
/**
* Listen for changes in the user.
* This method returns a unsubscribe function to stop listening to events.
* Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use.
*/
onUserChanged(listener: Function): () => void;
signOut(): Promise<void>
/**
* Sign an anonymous user.
* If the user has already signed in, that user will be returned
*/
signInAnonymously(): Promise<User>
/** /**
* We can create a user by calling the createUserWithEmailAndPassword() function. * We can create a user by calling the createUserWithEmailAndPassword() function.
@ -674,18 +768,6 @@ declare module "react-native-firebase" {
*/ */
signInWithEmailAndPassword(email: string, password: string): Promise<User> signInWithEmailAndPassword(email: string, password: string): Promise<User>
/**
* Sign an anonymous user.
* If the user has already signed in, that user will be returned
*/
signInAnonymously(): Promise<User>
/**
* Sign in the user with a 3rd party credential provider.
* credential requires the following properties:
*/
signInWithCredential(credential: Credential): Promise<User>
/** /**
* Sign a user in with a self-signed JWT token. * Sign a user in with a self-signed JWT token.
* To sign a user using a self-signed custom token, * To sign a user using a self-signed custom token,
@ -694,22 +776,40 @@ declare module "react-native-firebase" {
*/ */
signInWithCustomToken(token: string): Promise<User> signInWithCustomToken(token: string): Promise<User>
/**
* Sign in the user with a 3rd party credential provider.
* credential requires the following properties:
*/
signInWithCredential(credential: AuthCredential): Promise<User>
/**
* Asynchronously signs in using a phone number.
*/
signInWithPhoneNumber(phoneNumber: string): Promise<ConfirmationResult>
/**
* Returns a PhoneAuthListener to listen to phone verification events,
* on the final completion event a PhoneAuthCredential can be generated for
* authentication purposes.
*/
verifyPhoneNumber(phoneNumber: string, autoVerifyTimeout?: number): PhoneAuthListener
/** /**
* Sends a password reset email to the given email address. * Sends a password reset email to the given email address.
* Unlike the web SDK, * Unlike the web SDK,
* the email will contain a password reset link rather than a code. * the email will contain a password reset link rather than a code.
*/ */
sendPasswordResetEmail(email: string): Promise<void> sendPasswordResetEmail(email: string, actionCodeSettings?: ActionCodeSettings): Promise<void>
/** /**
* Completes the password reset process, given a confirmation code and new password. * Completes the password reset process, given a confirmation code and new password.
*/ */
confirmPasswordReset(code: string, newPassword: string): Promise<any> confirmPasswordReset(code: string, newPassword: string): Promise<void>
/** /**
* Applies a verification code sent to the user by email or other out-of-band mechanism. * Applies a verification code sent to the user by email or other out-of-band mechanism.
*/ */
applyActionCode(code: string): Promise<any> applyActionCode(code: string): Promise<void>
/** /**
* Checks a verification code sent to the user by email or other out-of-band mechanism. * Checks a verification code sent to the user by email or other out-of-band mechanism.
@ -717,10 +817,14 @@ declare module "react-native-firebase" {
checkActionCode(code: string): Promise<ActionCodeInfo> checkActionCode(code: string): Promise<ActionCodeInfo>
/** /**
* Completes the password reset process, * Get the currently signed in user
* given a confirmation code and new password.
*/ */
signOut(): Promise<void> getCurrentUser(): Promise<User | null>
/**
* Returns a list of authentication providers that can be used to sign in a given user (identified by its main email address).
*/
fetchProvidersForEmail(email: string): Promise<Array<string>>
[key: string]: any; [key: string]: any;
} }