7.0.1 • Published 2 years ago

cordova-plugin-firebase-authentication v7.0.1

Weekly downloads
424
License
MIT
Repository
github
Last release
2 years ago

Cordova plugin for Firebase Authentication

NPM version NPM downloads NPM total downloads Twitter

DonateYour help is appreciated. Create a PR, submit a bug or just grab me :beer:

Index

Supported Platforms

  • iOS
  • Android

Installation

cordova plugin add cordova-plugin-firebase-authentication

Use variables IOS_FIREBASE_POD_VERSION and ANDROID_FIREBASE_BOM_VERSION to override dependency versions for Firebase SDKs:

$ cordova plugin add cordova-plugin-firebase-authentication \
--variable IOS_FIREBASE_POD_VERSION="9.3.0" \
--variable ANDROID_FIREBASE_BOM_VERSION="30.3.1"

To use phone number authentication on iOS, your app must be able to receive silent APNs notifications from Firebase. For iOS 8.0 and above silent notifications do not require explicit user consent and is therefore unaffected by a user declining to receive APNs notifications in the app. Thus, the app does not need to request user permission to receive push notifications when implementing Firebase phone number auth.

Adding required configuration files

Cordova supports resource-file tag for easy copying resources files. Firebase SDK requires google-services.json on Android and GoogleService-Info.plist on iOS platforms.

  1. Put google-services.json and/or GoogleService-Info.plist into the root directory of your Cordova project
  2. Add new tag for Android platform
<platform name="android">
    ...
    <resource-file src="google-services.json" target="app/google-services.json" />
</platform>
...
<platform name="ios">
    ...
    <resource-file src="GoogleService-Info.plist" />
</platform>

Type Aliases

UserDetails

UserDetails: Object

Represents a user's profile information in your Firebase project's user database.

Type declaration

NameTypeDescription
displayNamestringMain display name of this user from the Firebase project's user database
emailstringMain email address of the user, as stored in the Firebase project's user database.
emailVerifiedbooleantrue if the user's email is verified.
phoneNumberstring | nullPhone number of the user, as stored in the Firebase project's user database, or null if none exists.
photoURLstringURL of this user's main profile picture, as stored in the Firebase project's user database.
providerIdstring-
uidstringString used to uniquely identify your user in your Firebase project's user database

Functions

createUserWithEmailAndPassword

createUserWithEmailAndPassword(email, password): Promise<void>

Creates a new user account with the given email address and password.

Example

cordova.plugins.firebase.auth.createUserWithEmailAndPassword("my@mail.com", "pa55w0rd");

Parameters

NameTypeDescription
emailstringUser account email
passwordstringUser accound password

Returns

Promise<void>

Callback when operation is completed


getCurrentUser

getCurrentUser(): Promise<UserDetails>

Returns the current user in the Firebase instance.

Returns

Promise<UserDetails>

Fulfills promise with user details


getIdToken

getIdToken(forceRefresh): Promise<string>

Returns a JWT token used to identify the user to a Firebase service.

Example

cordova.plugins.firebase.auth.getIdToken().then(function(idToken) {
    // send token to server
});

Parameters

NameTypeDescription
forceRefreshbooleanWhen true cached value is ignored

Returns

Promise<string>

Fulfills promis with id token string value


onAuthStateChanged

onAuthStateChanged(callback, errorCallback?): () => void

Registers a block as an auth state did change listener. To be invoked when:

  • The block is registered as a listener,
  • A user with a different UID from the current user has signed in, or
  • The current user has signed out.

Parameters

NameTypeDescription
callback(userDetails: UserDetails) => voidCallback function
errorCallback?(error: string) => voidError callback function

Returns

fn

(): void

Returns

void


sendEmailVerification

sendEmailVerification(): Promise<void>

Initiates email verification for the current user.

Example

cordova.plugins.firebase.auth.sendEmailVerification();

Returns

Promise<void>

Callback when operation is completed


sendPasswordResetEmail

sendPasswordResetEmail(email): Promise<void>

Triggers the Firebase Authentication backend to send a password-reset email to the given email address, which must correspond to an existing user of your app.

Example

cordova.plugins.firebase.auth.sendPasswordResetEmail("my@mail.com");

Parameters

NameTypeDescription
emailstringUser account email

Returns

Promise<void>

Callback when operation is completed


signInAnonymously

signInAnonymously(): Promise<void>

Create and use temporary anonymous account to authenticate with Firebase.

Example

cordova.plugins.firebase.auth.signInAnonymously();

Returns

Promise<void>

Callback when operation is completed


signInWithApple

signInWithApple(idToken, rawNonce): Promise<void>

Uses Apples's idToken and rawNonce to sign-in into firebase account. For getting idToken (rawNonce is optional) you can use cordova-plugin-sign-in-with-apple (or any other cordova plugin for Apple Sign-In).

See

Example

// below we use cordova-plugin-sign-in-with-apple to trigger Apple Login UI
cordova.plugins.SignInWithApple.signin({
    requestedScopes: [0, 1]
}, function(res) {
    cordova.plugins.firebase.auth.signInWithApple(res.identityToken).then(function() {
        console.log("Firebase logged in with Apple");
    }, function(err) {
        console.error("Firebase login failed", err);
    });
}, function(err) {
    console.error("Apple signin failed", err);
});

Parameters

NameTypeDescription
idTokenstringApple's ID token string
rawNoncestringApple's raw token string

Returns

Promise<void>

Callback when operation is completed


signInWithCustomToken

signInWithCustomToken(authToken): Promise<void>

You can integrate Firebase Authentication with a custom authentication system by modifying your authentication server to produce custom signed tokens when a user successfully signs in. Your app receives this token and uses it to authenticate with Firebase.

See

Parameters

NameTypeDescription
authTokenstringCustom auth token

Returns

Promise<void>

Callback when operation is completed


signInWithEmailAndPassword

signInWithEmailAndPassword(email, password): Promise<void>

Triggers the Firebase Authentication backend to send a password-reset email to the given email address, which must correspond to an existing user of your app.

Example

cordova.plugins.firebase.auth.signInWithEmailAndPassword("my@mail.com", "pa55w0rd");

Parameters

NameTypeDescription
emailstringUser account email
passwordstringUser accound password

Returns

Promise<void>

Callback when operation is completed


signInWithFacebook

signInWithFacebook(accessToken): Promise<void>

Uses Facebook's accessToken to sign-in into firebase account. In order to retrieve those tokens follow instructions for iOS and Android from Firebase docs.

See

Parameters

NameTypeDescription
accessTokenstringFacebook's access token string

Returns

Promise<void>

Callback when operation is completed


signInWithGoogle

signInWithGoogle(idToken, accessToken): Promise<void>

Uses Google's idToken and accessToken to sign-in into firebase account.

See

Example

// Below we use cordova-plugin-googleplus to trigger Google Login UI
window.plugins.googleplus.login({
    scopes: '... ',
    webClientId: '1234...',
    offline: true
}, function(res) {
    cordova.plugins.firebase.auth.signInWithGoogle(res.idToken, res.accessToken).then(function() {
        console.log("Firebase logged in with Google");
    }, function(err) {
        console.error("Firebase login failed", err);
    });
}, function(err) {
    console.error("Google login failed", err);
});

Parameters

NameTypeDescription
idTokenstringGoogle ID token
accessTokenstringGoogle Access token

Returns

Promise<void>

Callback when operation is completed


signInWithTwitter

signInWithTwitter(token, secret): Promise<void>

Uses Twitter's token and secret to sign-in into firebase account. In order to retrieve those tokens follow instructions for iOS and Android from Firebase docs.

See

Parameters

NameTypeDescription
tokenstringTwitter's token string
secretstringTwitter's secret string

Returns

Promise<void>

Callback when operation is completed


signInWithVerificationId

signInWithVerificationId(verificationId, code): Promise<void>

Completes phone number verification process and use it to sign in.

Example

cordova.plugins.firebase.auth.verifyPhoneNumber("+123456789").then(function(verificationId) {
    var code = prompt("Enter verification code");
    if (code) {
        return cordova.plugins.firebase.auth.signInWithVerificationId(verificationId, code);
    }
}).catch(function(err) {
    console.error("Phone number verification failed", err);
});

Parameters

NameTypeDescription
verificationIdstringdescription
codestring6-digit SMS code

Returns

Promise<void>

Callback when operation is completed


signOut

signOut(): Promise<void>

Signs out the current user and clears it from the disk cache.

Example

cordova.plugins.firebase.auth.signOut();

Returns

Promise<void>

Callback when operation is completed


updateProfile

updateProfile(profileDetails): Promise<void>

Updates the current user's profile data. Passing a null value will delete the current attribute's value, but not passing a property won't change the current attribute's value.

Example

cordova.plugins.firebase.auth.updateProfile({
    displayName: "Jane Q. User",
    photoURL: "https://example.com/jane-q-user/profile.jpg",
});

Parameters

NameTypeDescription
profileDetailsObjectUser attributes.
profileDetails.displayNamestring-
profileDetails.photoURLstring-

Returns

Promise<void>

Callback when operation is completed


useAppLanguage

useAppLanguage(): Promise<void>

Sets languageCode to the app’s current language.

Example

cordova.plugins.firebase.auth.useAppLanguage();

Returns

Promise<void>

Callback when operation is completed


useEmulator

useEmulator(host, port): Promise<void>

Sets languageCode to the app’s current language.

Example

cordova.plugins.firebase.auth.useEmulator('localhost', 8000);

Parameters

NameTypeDescription
hoststringEmulator host name
portnumberEmulator port

Returns

Promise<void>

Callback when operation is completed


verifyPhoneNumber

verifyPhoneNumber(phoneNumber, timeoutMillis?): Promise<string>

Starts the phone number verification process for the given phone number.

Android supports auto-verify and instant device verification. You must register onAuthStateChanged to get callback on instant verification.

Maximum allowed value for timeout is 2 minutes. Use 0 to disable SMS-auto-retrieval. If you specify a positive value less than 30 seconds, library will default to 30 seconds.

Parameters

NameTypeDescription
phoneNumberstringPhone number in international format
timeoutMillis?numberMaximum amount of time you are willing to wait for SMS auto-retrieval to be completed by the library.

Returns

Promise<string>

Fulfills promise with verificationId to use later for signing in

7.0.0

2 years ago

7.0.1

2 years ago

5.1.0

2 years ago

5.0.0

3 years ago

4.0.2

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.6.0

4 years ago

3.5.0

4 years ago

3.4.1

4 years ago

3.4.0

4 years ago

3.3.1

4 years ago

3.3.0

4 years ago

3.2.0

4 years ago

3.1.0

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.14.1

6 years ago

0.14.0

6 years ago

0.13.2

6 years ago

0.13.1

6 years ago

0.13.0

6 years ago

0.12.1

6 years ago

0.12.0

6 years ago

0.11.1

7 years ago

0.10.1

7 years ago

0.10.0

7 years ago