@imnotout/capacitor-firebase-phoneauth
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

Capacitor-firebase-phoneauth

This plugins was intended to be used internally at imnotout.com. Works only with Web and iOS. Code can be used as is or for reference under GNU GPLv3 License.

  /**
   * Requests otp from firebase to authenticate and verify phone number.
   * @param options accepts phone number as string with countrycode, eg: +919999999999
   */
  verifyPhoneNumber(options: VerifyPhoneNumberOptions): Promise<void>

  /**
   *  verifies the otp and authenticates a user
   * @param options
   */
  signinWithOtp(options: SigninWithOtpOptions): Promise<{ uid: string }>

  /**
   * Logouts the current authenticated user
   */
  signOut(): Promise<void>

  /**
   * Returns the idToken of current authenticated user
   */
  getIdToken(): Promise<{ token: String }>

  /**
   * Calls callback with user is signed in or out (err, user)
   * @param callback
   */
  onAuthStateChanged(callback: {
    (error: any, user: { uid: string } | null): void
  }): void

Special instructions for web

before calling any method set the fiebase instance to be used since we can't initialise here inside plugin, you may require firebase is required outside the plugin.

/**
 * Set firebase instance for use with web [REQUIRED].
 * You can get the initialized firebase instance from firebase.app()
 * EG: CapacitorFirebasePhoneAuth.setFirebaseInstanceForWeb(fb: firebase.app.App)
 * @param firebase
 */
setFirebaseInstanceForWeb(fb: firebase.app.App):void

Usage

import { Plugins } from "@capacitor/core"

const { CapacitorFirebasePhoneAuth } = Plugins

//Use await or a regular promise
const token = await CapacitorFirebasePhoneAuth.getIdToken()

Readme

Keywords

Package Sidebar

Install

npm i @imnotout/capacitor-firebase-phoneauth

Weekly Downloads

0

Version

1.0.8

License

GPLV3

Unpacked Size

3.18 MB

Total Files

521

Last publish

Collaborators

  • saikiran.dev