Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

Firebase Authentication

Improve this doc

Cordova plugin for Firebase Authentication

Repo: https://github.com/chemerisuk/cordova-plugin-firebase-authentication

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-firebase-authentication --variable FIREBASE_AUTH_VERSION=version
    $ npm install --save @ionic-native/firebase-authentication@4
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { FirebaseAuthentication } from '@ionic-native/firebase-authentication';


constructor(private firebaseAuthentication: FirebaseAuthentication) { }

...


this.firebaseAuthentication.createUserWithEmailAndPassword('test@gmail.com', '123')
  .then((res: any) => console.log(res))
  .catch((error: any) => console.error(error));

Instance Members

getIdToken(forceRefresh)

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

Param Type Details
forceRefresh boolean

Force Refresh

Returns: Promise<any> Returns the id token

createUserWithEmailAndPassword(email, password)

Tries to create a new user account with the given email address and password.

Param Type Details
email

Email

password

Password

sendEmailVerification()

Initiates email verification for the current user.

sendPasswordResetEmail(email)

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.

Param Type Details
email

Email

signInWithEmailAndPassword(email, password)

Asynchronously signs in using an email and password.

Param Type Details
email

Email

password

Password

verifyPhoneNumber(phoneNumber, timeout)

Starts the phone number verification process for the given phone number. NOTE: Android supports auto-verify and instant device verification. Therefore in that cases it doesn’t make sense to ask for sms code. It’s recommended to register onAuthStateChanged callback to be notified on auto sign-in. timeout [milliseconds] is the maximum amount of time you are willing to wait for SMS auto-retrieval to be completed by the library. Maximum allowed value 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.

Param Type Details
phoneNumber

Phone number

timeout number

Timeout

signInWithVerificationId(verificationId, smsCode)

Asynchronously signs in using verificationId and 6-digit SMS code.

Param Type Details
verificationId

Verification ID

smsCode

SMS code

signInAnonymously()

Create and use temporary anonymous account to authenticate with Firebase.

signInWithGoogle(idToken, accessToken)

Uses Google’s idToken and accessToken to sign-in into firebase account. In order to retrieve those tokens follow instructions for Android and iOS

Param Type Details
idToken

ID Token

accessToken

Access Token

signInWithFacebook(accessToken)

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

Param Type Details
accessToken

Access Token

signInWithTwitter(token, secret)

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

Param Type Details
token

Token

secret

Secret

onAuthStateChanged()

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

setLanguageCode(languageCode)

Set’s the current user language code. The string used to set this property must be a language code that follows BCP 47.

Param Type Details
languageCode

Language Code

useAppLanguage()

Sets languageCode to the app’s current language.

signOut()

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

API

Native

General