npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-firebase-authentication

v7.0.1

Published

Cordova plugin for Firebase Authentication

Downloads

324

Readme

Cordova plugin for Firebase Authentication

NPM version NPM downloads NPM total downloads Twitter

| Donate | Your 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

| Name | Type | Description | | :------ | :------ | :------ | | displayName | string | Main display name of this user from the Firebase project's user database | | email | string | Main email address of the user, as stored in the Firebase project's user database. | | emailVerified | boolean | true if the user's email is verified. | | phoneNumber | string | null | Phone number of the user, as stored in the Firebase project's user database, or null if none exists. | | photoURL | string | URL of this user's main profile picture, as stored in the Firebase project's user database. | | providerId | string | - | | uid | string | String 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("[email protected]", "pa55w0rd");

Parameters

| Name | Type | Description | | :------ | :------ | :------ | | email | string | User account email | | password | string | User 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

| Name | Type | Description | | :------ | :------ | :------ | | forceRefresh | boolean | When 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

| Name | Type | Description | | :------ | :------ | :------ | | callback | (userDetails: UserDetails) => void | Callback function | | errorCallback? | (error: string) => void | Error 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("[email protected]");

Parameters

| Name | Type | Description | | :------ | :------ | :------ | | email | string | User 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

  • https://firebase.google.com/docs/auth/android/apple
  • https://firebase.google.com/docs/auth/ios/apple

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

| Name | Type | Description | | :------ | :------ | :------ | | idToken | string | Apple's ID token string | | rawNonce | string | Apple'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

  • https://firebase.google.com/docs/auth/android/custom-auth
  • https://firebase.google.com/docs/auth/ios/custom-auth

Parameters

| Name | Type | Description | | :------ | :------ | :------ | | authToken | string | Custom 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("[email protected]", "pa55w0rd");

Parameters

| Name | Type | Description | | :------ | :------ | :------ | | email | string | User account email | | password | string | User 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

  • https://firebase.google.com/docs/auth/android/facebook-login
  • https://firebase.google.com/docs/auth/ios/facebook-login

Parameters

| Name | Type | Description | | :------ | :------ | :------ | | accessToken | string | Facebook'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

  • https://firebase.google.com/docs/auth/android/google-signin
  • https://firebase.google.com/docs/auth/ios/google-signin

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

| Name | Type | Description | | :------ | :------ | :------ | | idToken | string | Google ID token | | accessToken | string | Google 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

  • https://firebase.google.com/docs/auth/android/twitter-login
  • https://firebase.google.com/docs/auth/ios/twitter-login

Parameters

| Name | Type | Description | | :------ | :------ | :------ | | token | string | Twitter's token string | | secret | string | Twitter'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

| Name | Type | Description | | :------ | :------ | :------ | | verificationId | string | [description] | | code | string | 6-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

| Name | Type | Description | | :------ | :------ | :------ | | profileDetails | Object | User attributes. | | profileDetails.displayName | string | - | | profileDetails.photoURL | string | - |

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

| Name | Type | Description | | :------ | :------ | :------ | | host | string | Emulator host name | | port | number | Emulator 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

| Name | Type | Description | | :------ | :------ | :------ | | phoneNumber | string | Phone number in international format | | timeoutMillis? | number | Maximum 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