Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@capacitor-firebase/authentication

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@capacitor-firebase/authentication

Capacitor plugin for Firebase Authentication.

  • 6.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10K
decreased by-4.3%
Maintainers
1
Weekly downloads
 
Created
Source

@capacitor-firebase/authentication

Unofficial Capacitor plugin for Firebase Authentication.1

Installation

npm install @capacitor-firebase/authentication firebase
npx cap sync

Add Firebase to your project if you haven't already (Android / iOS / Web).

On iOS, verify that this function is included in your app's AppDelegate.swift:

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
  return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
}

Attention: If you use this plugin on iOS in combination with @capacitor-firebase/messaging, then add the following to your app's AppDelegate.swift:

+ import FirebaseAuth

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
+    if Auth.auth().canHandle(url) {
+      return true
+    }
    return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
}

The further installation steps depend on the selected authentication method:

Attention: Please note that this plugin uses third-party SDKs to offer native sign-in. These SDKs can initialize on their own and collect various data. For more information, see Third-Party SDKs.

Configuration

These configuration values are available:

PropTypeDescriptionDefaultSince
skipNativeAuthbooleanConfigure whether the plugin should skip the native authentication. Only needed if you want to use the Firebase JavaScript SDK. This configuration option has no effect on Firebase account linking. Note that the plugin may behave differently across the platforms. Only available for Android and iOS.false0.1.0
providersstring[]Configure the providers that should be loaded by the plugin. Possible values: ["apple.com", "facebook.com", "gc.apple.com", "github.com", "google.com", "microsoft.com", "playgames.google.com", "twitter.com", "yahoo.com", "phone"] Only available for Android and iOS.[]0.1.0

Examples

In capacitor.config.json:

{
  "plugins": {
    "FirebaseAuthentication": {
      "skipNativeAuth": false,
      "providers": ["apple.com", "facebook.com"]
    }
  }
}

In capacitor.config.ts:

/// <reference types="@capacitor-firebase/authentication" />

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  plugins: {
    FirebaseAuthentication: {
      skipNativeAuth: false,
      providers: ["apple.com", "facebook.com"],
    },
  },
};

export default config;

FAQ

  1. What does this plugin do?
    This plugin enables the use of Firebase Authentication in a Capacitor app. It uses the Firebase SDK for Java (Android), Swift (iOS) and JavaScript.
  2. What is the difference between the web implementation of this plugin and the Firebase JS SDK?
    The web implementation of this plugin encapsulates the Firebase JS SDK and enables a consistent interface across all platforms. You can decide if you prefer to use the web implementation or the Firebase JS SDK.
  3. What is the difference between the native and web authentication?
    For web authentication, the Firebase JS SDK is used. This only works to a limited extent on Android and iOS in the WebViews (see here). For native authentication, the native SDKs from Firebase, Google, etc. are used. These offer all the functionalities that the Firebase JS SDK also offers on the web. However, after a login with the native SDK, the user is only logged in on the native layer of the app. If the user should also be logged in on the web layer (for example to access Cloud Firestore via Firebase JS SDK), additional steps are required (see here).
  4. How can I use this plugin with the Firebase JavaScript SDK?
    See here.

Firebase JavaScript SDK

Here you can find information on how to use the plugin with the Firebase JS SDK.

Demo

A working example can be found here: robingenz/capacitor-firebase-authentication-demo

Starter templates

The following starter templates are available:

Usage

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

const applyActionCode = async () => {
  await FirebaseAuthentication.applyActionCode({ oobCode: '1234' });
};

const createUserWithEmailAndPassword = async () => {
  const result = await FirebaseAuthentication.createUserWithEmailAndPassword({
    email: 'mail@exmaple.com',
    password: '1234',
  });
  return result.user;
};

const confirmPasswordReset = async () => {
  await FirebaseAuthentication.confirmPasswordReset({
    oobCode: '1234',
    newPassword: '4321',
  });
};

const deleteUser = async () => {
  await FirebaseAuthentication.deleteUser();
};

const fetchSignInMethodsForEmail = async () => {
  const result = await FirebaseAuthentication.fetchSignInMethodsForEmail({
    email: 'mail@example.tld',
  });
  return result.signInMethods;
};

const getCurrentUser = async () => {
  const result = await FirebaseAuthentication.getCurrentUser();
  return result.user;
};

const getPendingAuthResult = async () => {
  const result = await FirebaseAuthentication.getPendingAuthResult();
  return result.user;
};

const getIdToken = async () => {
  const currentUser = await getCurrentUser();
  if (!currentUser) {
    return;
  }
  const result = await FirebaseAuthentication.getIdToken();
  return result.token;
};

const getPendingAuthResult = async () => {
  const result = await FirebaseAuthentication.getPendingAuthResult();
  return result.user;
};

const sendEmailVerification = async () => {
  const currentUser = await getCurrentUser();
  if (!currentUser) {
    return;
  }
  await FirebaseAuthentication.sendEmailVerification();
};

const sendPasswordResetEmail = async () => {
  await FirebaseAuthentication.sendPasswordResetEmail({
    email: 'mail@example.com',
  });
};

const sendSignInLinkToEmail = async () => {
  const email = 'mail@example.com';
  await FirebaseAuthentication.sendSignInLinkToEmail({
    email,
    actionCodeSettings: {
      // URL you want to redirect back to. The domain (www.example.com) for this
      // URL must be in the authorized domains list in the Firebase Console.
      url: 'https://www.example.com/finishSignUp?cartId=1234',
      // This must be true.
      handleCodeInApp: true,
      iOS: {
        bundleId: 'com.example.ios',
      },
      android: {
        packageName: 'com.example.android',
        installApp: true,
        minimumVersion: '12',
      },
      dynamicLinkDomain: 'example.page.link',
    },
  });
  // The link was successfully sent. Inform the user.
  // Save the email locally so you don't need to ask the user for it again
  // if they open the link on the same device.
  window.localStorage.setItem('emailForSignIn', email);
};

const setLanguageCode = async () => {
  await FirebaseAuthentication.setLanguageCode({ languageCode: 'en-US' });
};

const signInAnonymously = async () => {
  const result = await FirebaseAuthentication.signInAnonymously();
  return result.user;
};

const signInWithApple = async () => {
  const result = await FirebaseAuthentication.signInWithApple();
  return result.user;
};

const signInWithCustomToken = async () => {
  const result = await FirebaseAuthentication.signInWithCustomToken({
    token: '1234',
  });
  return result.user;
};

const signInWithEmailAndPassword = async () => {
  const result = await FirebaseAuthentication.signInWithEmailAndPassword({
    email: 'mail@example.com',
    password: '1234',
  });
  return result.user;
};

const signInWithEmailLink = async () => {
  // Get the email if available. This should be available if the user completes
  // the flow on the same device where they started it.
  const emailLink = window.location.href;
  // Confirm the link is a sign-in with email link.
  const { isSignInWithEmailLink } =
    await FirebaseAuthentication.isSignInWithEmailLink({
      emailLink,
    });
  if (!isSignInWithEmailLink) {
    return;
  }
  let email = window.localStorage.getItem('emailForSignIn');
  if (!email) {
    // User opened the link on a different device. To prevent session fixation
    // attacks, ask the user to provide the associated email again.
    email = window.prompt('Please provide your email for confirmation.');
  }
  // The client SDK will parse the code from the link for you.
  const result = await FirebaseAuthentication.signInWithEmailLink({
    email,
    emailLink,
  });
  // Clear email from storage.
  window.localStorage.removeItem('emailForSignIn');
  return result.user;
};

const signInWithFacebook = async () => {
  const result = await FirebaseAuthentication.signInWithFacebook();
  return result.user;
};

const signInWithGameCenter = async () => {
  const result = await FirebaseAuthentication.signInWithGameCenter();
  return result.user;
};

const signInWithGithub = async () => {
  const result = await FirebaseAuthentication.signInWithGithub();
  return result.user;
};

const signInWithGoogle = async () => {
  const result = await FirebaseAuthentication.signInWithGoogle();
  return result.user;
};

const signInWithMicrosoft = async () => {
  const result = await FirebaseAuthentication.signInWithMicrosoft();
  return result.user;
};

const signInWithOpenIdConnect = async () => {
  const result = await FirebaseAuthentication.signInWithOpenIdConnect({
    providerId: 'oidc.example.com',
  });
  return result.user;
};

const signInWithPlayGames = async () => {
  const result = await FirebaseAuthentication.signInWithPlayGames();
  return result.user;
};

const signInWithPhoneNumber = async () => {
  return new Promise(async resolve => {
    // Attach `phoneCodeSent` listener to be notified as soon as the SMS is sent
    await FirebaseAuthentication.addListener('phoneCodeSent', async event => {
      // Ask the user for the SMS code
      const verificationCode = window.prompt(
        'Please enter the verification code that was sent to your mobile device.',
      );
      // Confirm the verification code
      const result = await FirebaseAuthentication.confirmVerificationCode({
        verificationId: event.verificationId,
        verificationCode,
      });
      resolve(result.user);
    });
    // Attach `phoneVerificationCompleted` listener to be notified if phone verification could be finished automatically
    await FirebaseAuthentication.addListener(
      'phoneVerificationCompleted',
      async event => {
        resolve(event.result.user);
      },
    );
    // Start sign in with phone number and send the SMS
    await FirebaseAuthentication.signInWithPhoneNumber({
      phoneNumber: '123456789',
    });
  });
};

const signInWithTwitter = async () => {
  const result = await FirebaseAuthentication.signInWithTwitter();
  return result.user;
};

const signInWithYahoo = async () => {
  const result = await FirebaseAuthentication.signInWithYahoo();
  return result.user;
};

const signOut = async () => {
  await FirebaseAuthentication.signOut();
};

const updateEmail = async () => {
  const currentUser = await getCurrentUser();
  if (!currentUser) {
    return;
  }
  await FirebaseAuthentication.updateEmail({
    newEmail: 'new.mail@example.com',
  });
};

const updatePassword = async () => {
  const currentUser = await getCurrentUser();
  if (!currentUser) {
    return;
  }
  await FirebaseAuthentication.updatePassword({
    newPassword: '4321',
  });
};

const useAppLanguage = async () => {
  await FirebaseAuthentication.useAppLanguage();
};

const useEmulator = async () => {
  await FirebaseAuthentication.useEmulator({
    host: '10.0.2.2',
    port: 9099,
  });
};

API

applyActionCode(...)

applyActionCode(options: ApplyActionCodeOptions) => Promise<void>

Applies a verification code sent to the user by email.

ParamType
optionsApplyActionCodeOptions

Since: 0.2.2


confirmPasswordReset(...)

confirmPasswordReset(options: ConfirmPasswordResetOptions) => Promise<void>

Completes the password reset process.

ParamType
optionsConfirmPasswordResetOptions

Since: 0.2.2


confirmVerificationCode(...)

confirmVerificationCode(options: ConfirmVerificationCodeOptions) => Promise<SignInResult>

Finishes the phone number verification process.

ParamType
optionsConfirmVerificationCodeOptions

Returns: Promise<SignInResult>

Since: 5.0.0


createUserWithEmailAndPassword(...)

createUserWithEmailAndPassword(options: CreateUserWithEmailAndPasswordOptions) => Promise<SignInResult>

Creates a new user account with email and password. If the new account was created, the user is signed in automatically.

ParamType
optionsCreateUserWithEmailAndPasswordOptions

Returns: Promise<SignInResult>

Since: 0.2.2


deleteUser()

deleteUser() => Promise<void>

Deletes and signs out the user.

Since: 1.3.0


fetchSignInMethodsForEmail(...)

fetchSignInMethodsForEmail(options: FetchSignInMethodsForEmailOptions) => Promise<FetchSignInMethodsForEmailResult>

Fetches the sign-in methods for an email address.

ParamType
optionsFetchSignInMethodsForEmailOptions

Returns: Promise<FetchSignInMethodsForEmailResult>

Since: 6.0.0


getCurrentUser()

getCurrentUser() => Promise<GetCurrentUserResult>

Fetches the currently signed-in user.

Returns: Promise<GetCurrentUserResult>

Since: 0.1.0


getPendingAuthResult()

getPendingAuthResult() => Promise<SignInResult>

Returns the SignInResult if your app launched a web sign-in flow and the OS cleans up the app while in the background.

Only available for Android.

Returns: Promise<SignInResult>

Since: 6.0.0


getIdToken(...)

getIdToken(options?: GetIdTokenOptions | undefined) => Promise<GetIdTokenResult>

Fetches the Firebase Auth ID Token for the currently signed-in user.

ParamType
optionsGetIdTokenOptions

Returns: Promise<GetIdTokenResult>

Since: 0.1.0


getRedirectResult()

getRedirectResult() => Promise<SignInResult>

Returns the SignInResult from the redirect-based sign-in flow.

If sign-in was unsuccessful, fails with an error. If no redirect operation was called, returns a SignInResult with a null user.

Only available for Web.

Returns: Promise<SignInResult>

Since: 1.3.0


getTenantId()

getTenantId() => Promise<GetTenantIdResult>

Get the tenant id.

Returns: Promise<GetTenantIdResult>

Since: 1.1.0


isSignInWithEmailLink(options: IsSignInWithEmailLinkOptions) => Promise<IsSignInWithEmailLinkResult>

Checks if an incoming link is a sign-in with email link suitable for signInWithEmailLink.

ParamType
optionsIsSignInWithEmailLinkOptions

Returns: Promise<IsSignInWithEmailLinkResult>

Since: 1.1.0


linkWithApple(...)

linkWithApple(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

Links the user account with Apple authentication provider.

The user must be logged in on the native layer. The skipNativeAuth configuration option has no effect here.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 1.1.0


linkWithEmailAndPassword(...)

linkWithEmailAndPassword(options: LinkWithEmailAndPasswordOptions) => Promise<LinkResult>

Links the user account with Email authentication provider.

The user must be logged in on the native layer. The skipNativeAuth configuration option has no effect here.

ParamType
optionsLinkWithEmailAndPasswordOptions

Returns: Promise<SignInResult>

Since: 1.1.0


linkWithEmailLink(options: LinkWithEmailLinkOptions) => Promise<LinkResult>

Links the user account with Email authentication provider.

The user must be logged in on the native layer. The skipNativeAuth configuration option has no effect here.

ParamType
optionsLinkWithEmailLinkOptions

Returns: Promise<SignInResult>

Since: 1.1.0


linkWithFacebook(...)

linkWithFacebook(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

Links the user account with Facebook authentication provider.

The user must be logged in on the native layer. The skipNativeAuth configuration option has no effect here.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 1.1.0


linkWithGameCenter(...)

linkWithGameCenter(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

Links the user account with Game Center authentication provider.

The user must be logged in on the native layer. The skipNativeAuth configuration option has no effect here.

Only available for iOS.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 1.3.0


linkWithGithub(...)

linkWithGithub(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

Links the user account with GitHub authentication provider.

The user must be logged in on the native layer. The skipNativeAuth configuration option has no effect here.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 1.1.0


linkWithGoogle(...)

linkWithGoogle(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

Links the user account with Google authentication provider.

The user must be logged in on the native layer. The skipNativeAuth configuration option has no effect here.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 1.1.0


linkWithMicrosoft(...)

linkWithMicrosoft(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

Links the user account with Microsoft authentication provider.

The user must be logged in on the native layer. The skipNativeAuth configuration option has no effect here.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 1.1.0


linkWithOpenIdConnect(...)

linkWithOpenIdConnect(options: LinkWithOpenIdConnectOptions) => Promise<LinkResult>

Links the user account with an OpenID Connect provider.

ParamType
optionsSignInWithOpenIdConnectOptions

Returns: Promise<SignInResult>

Since: 6.1.0


linkWithPhoneNumber(...)

linkWithPhoneNumber(options: LinkWithPhoneNumberOptions) => Promise<void>

Links the user account with Phone Number authentication provider.

The user must be logged in on the native layer. The skipNativeAuth configuration option has no effect here.

Use the phoneVerificationCompleted listener to be notified when the verification is completed. Use the phoneVerificationFailed listener to be notified when the verification is failed. Use the phoneCodeSent listener to get the verification id.

ParamType
optionsSignInWithPhoneNumberOptions

Since: 1.1.0


linkWithPlayGames(...)

linkWithPlayGames(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

Links the user account with Play Games authentication provider.

The user must be logged in on the native layer. The skipNativeAuth configuration option has no effect here.

Only available for Android.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 1.1.0


linkWithTwitter(...)

linkWithTwitter(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

Links the user account with Twitter authentication provider.

The user must be logged in on the native layer. The skipNativeAuth configuration option has no effect here.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 1.1.0


linkWithYahoo(...)

linkWithYahoo(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

Links the user account with Yahoo authentication provider.

The user must be logged in on the native layer. The skipNativeAuth configuration option has no effect here.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 1.1.0


reload()

reload() => Promise<void>

Reloads user account data, if signed in.

Since: 1.3.0


revokeAccessToken(...)

revokeAccessToken(options: RevokeAccessTokenOptions) => Promise<void>

Revokes the given access token. Currently only supports Apple OAuth access tokens.

ParamType
optionsRevokeAccessTokenOptions

Since: 6.1.0


sendEmailVerification(...)

sendEmailVerification(options?: SendEmailVerificationOptions | undefined) => Promise<void>

Sends a verification email to the currently signed in user.

ParamType
optionsSendEmailVerificationOptions

Since: 0.2.2


sendPasswordResetEmail(...)

sendPasswordResetEmail(options: SendPasswordResetEmailOptions) => Promise<void>

Sends a password reset email.

ParamType
optionsSendPasswordResetEmailOptions

Since: 0.2.2


sendSignInLinkToEmail(...)

sendSignInLinkToEmail(options: SendSignInLinkToEmailOptions) => Promise<void>

Sends a sign-in email link to the user with the specified email.

To complete sign in with the email link, call signInWithEmailLink with the email address and the email link supplied in the email sent to the user.

ParamType
optionsSendSignInLinkToEmailOptions

Since: 1.1.0


setLanguageCode(...)

setLanguageCode(options: SetLanguageCodeOptions) => Promise<void>

Sets the user-facing language code for auth operations.

ParamType
optionsSetLanguageCodeOptions

Since: 0.1.0


setPersistence(...)

setPersistence(options: SetPersistenceOptions) => Promise<void>

Sets the type of persistence for the currently saved auth session.

Only available for Web.

ParamType
optionsSetPersistenceOptions

Since: 5.2.0


setTenantId(...)

setTenantId(options: SetTenantIdOptions) => Promise<void>

Sets the tenant id.

ParamType
optionsSetTenantIdOptions

Since: 1.1.0


signInAnonymously()

signInAnonymously() => Promise<SignInResult>

Signs in as an anonymous user.

Returns: Promise<SignInResult>

Since: 1.1.0


signInWithApple(...)

signInWithApple(options?: SignInWithOAuthOptions | undefined) => Promise<SignInResult>

Starts the Apple sign-in flow.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 0.1.0


signInWithCustomToken(...)

signInWithCustomToken(options: SignInWithCustomTokenOptions) => Promise<SignInResult>

Starts the Custom Token sign-in flow.

This method cannot be used in combination with skipNativeAuth on Android and iOS. In this case you have to use the signInWithCustomToken interface of the Firebase JS SDK directly.

ParamType
optionsSignInWithCustomTokenOptions

Returns: Promise<SignInResult>

Since: 0.1.0


signInWithEmailAndPassword(...)

signInWithEmailAndPassword(options: SignInWithEmailAndPasswordOptions) => Promise<SignInResult>

Starts the sign-in flow using an email and password.

ParamType
optionsSignInWithEmailAndPasswordOptions

Returns: Promise<SignInResult>

Since: 0.2.2


signInWithEmailLink(options: SignInWithEmailLinkOptions) => Promise<SignInResult>

Signs in using an email and sign-in email link.

ParamType
optionsSignInWithEmailLinkOptions

Returns: Promise<SignInResult>

Since: 1.1.0


signInWithFacebook(...)

signInWithFacebook(options?: SignInWithOAuthOptions | undefined) => Promise<SignInResult>

Starts the Facebook sign-in flow.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 0.1.0


signInWithGameCenter(...)

signInWithGameCenter(options?: SignInWithOAuthOptions | SignInOptions | undefined) => Promise<SignInResult>

Starts the Game Center sign-in flow.

Only available for iOS.

ParamType
optionsSignInWithOAuthOptions | SignInOptions

Returns: Promise<SignInResult>

Since: 1.3.0


signInWithGithub(...)

signInWithGithub(options?: SignInWithOAuthOptions | undefined) => Promise<SignInResult>

Starts the GitHub sign-in flow.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 0.1.0


signInWithGoogle(...)

signInWithGoogle(options?: SignInWithOAuthOptions | undefined) => Promise<SignInResult>

Starts the Google sign-in flow.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 0.1.0


signInWithMicrosoft(...)

signInWithMicrosoft(options?: SignInWithOAuthOptions | undefined) => Promise<SignInResult>

Starts the Microsoft sign-in flow.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 0.1.0


signInWithOpenIdConnect(...)

signInWithOpenIdConnect(options: SignInWithOpenIdConnectOptions) => Promise<SignInResult>

Starts the OpenID Connect sign-in flow.

ParamType
optionsSignInWithOpenIdConnectOptions

Returns: Promise<SignInResult>

Since: 6.1.0


signInWithPhoneNumber(...)

signInWithPhoneNumber(options: SignInWithPhoneNumberOptions) => Promise<void>

Starts the sign-in flow using a phone number.

Use the phoneVerificationCompleted listener to be notified when the verification is completed. Use the phoneVerificationFailed listener to be notified when the verification is failed. Use the phoneCodeSent listener to get the verification id.

Only available for Android and iOS.

ParamType
optionsSignInWithPhoneNumberOptions

Since: 0.1.0


signInWithPlayGames(...)

signInWithPlayGames(options?: SignInWithOAuthOptions | undefined) => Promise<SignInResult>

Starts the Play Games sign-in flow.

Only available for Android.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 0.1.0


signInWithTwitter(...)

signInWithTwitter(options?: SignInWithOAuthOptions | undefined) => Promise<SignInResult>

Starts the Twitter sign-in flow.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 0.1.0


signInWithYahoo(...)

signInWithYahoo(options?: SignInWithOAuthOptions | undefined) => Promise<SignInResult>

Starts the Yahoo sign-in flow.

ParamType
optionsSignInWithOAuthOptions

Returns: Promise<SignInResult>

Since: 0.1.0


signOut()

signOut() => Promise<void>

Starts the sign-out flow.

Since: 0.1.0


unlink(options: UnlinkOptions) => Promise<UnlinkResult>

Unlinks a provider from a user account.

ParamType
optionsUnlinkOptions

Returns: Promise<UnlinkResult>

Since: 1.1.0


updateEmail(...)

updateEmail(options: UpdateEmailOptions) => Promise<void>

Updates the email address of the currently signed in user.

ParamType
optionsUpdateEmailOptions

Since: 0.1.0


updatePassword(...)

updatePassword(options: UpdatePasswordOptions) => Promise<void>

Updates the password of the currently signed in user.

ParamType
optionsUpdatePasswordOptions

Since: 0.1.0


updateProfile(...)

updateProfile(options: UpdateProfileOptions) => Promise<void>

Updates a user's profile data.

ParamType
optionsUpdateProfileOptions

Since: 1.3.0


useAppLanguage()

useAppLanguage() => Promise<void>

Sets the user-facing language code to be the default app language.

Since: 0.1.0


useEmulator(...)

useEmulator(options: UseEmulatorOptions) => Promise<void>

Instrument your app to talk to the Authentication emulator.

ParamType
optionsUseEmulatorOptions

Since: 0.2.0


addListener('authStateChange', ...)

addListener(eventName: 'authStateChange', listenerFunc: AuthStateChangeListener) => Promise<PluginListenerHandle>

Listen for the user's sign-in state changes.

Attention: This listener is not triggered when the skipNativeAuth is used. Use the Firebase JavaScript SDK instead.

ParamType
eventName'authStateChange'
listenerFuncAuthStateChangeListener

Returns: Promise<PluginListenerHandle>

Since: 0.1.0


addListener('phoneVerificationCompleted', ...)

addListener(eventName: 'phoneVerificationCompleted', listenerFunc: PhoneVerificationCompletedListener) => Promise<PluginListenerHandle>

Listen for a completed phone verification.

This listener only fires in two situations:

  1. Instant verification: In some cases the phone number can be instantly verified without needing to send or enter a verification code.
  2. Auto-retrieval: On some devices Google Play services can automatically detect the incoming verification SMS and perform verification without user action.

Only available for Android.

ParamType
eventName'phoneVerificationCompleted'
listenerFuncPhoneVerificationCompletedListener

Returns: Promise<PluginListenerHandle>

Since: 1.3.0


addListener('phoneVerificationFailed', ...)

addListener(eventName: 'phoneVerificationFailed', listenerFunc: PhoneVerificationFailedListener) => Promise<PluginListenerHandle>

Listen for a failed phone verification.

ParamType
eventName'phoneVerificationFailed'
listenerFuncPhoneVerificationFailedListener

Returns: Promise<PluginListenerHandle>

Since: 1.3.0


addListener('phoneCodeSent', ...)

addListener(eventName: 'phoneCodeSent', listenerFunc: PhoneCodeSentListener) => Promise<PluginListenerHandle>

Listen for a phone verification code.

ParamType
eventName'phoneCodeSent'
listenerFuncPhoneCodeSentListener

Returns: Promise<PluginListenerHandle>

Since: 1.3.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for this plugin.

Since: 0.1.0


Interfaces

ApplyActionCodeOptions
PropTypeDescriptionSince
oobCodestringA verification code sent to the user.0.2.2
ConfirmPasswordResetOptions
PropTypeDescriptionSince
oobCodestringA verification code sent to the user.0.2.2
newPasswordstringThe new password.0.2.2
SignInResult
PropTypeDescriptionSince
userUser | nullThe currently signed-in user, or null if there isn't any.0.1.0
credentialAuthCredential | nullCredentials returned by an auth provider.0.1.0
additionalUserInfoAdditionalUserInfo | nullAdditional user information from a federated identity provider.0.5.1
User
PropTypeDescriptionSince
displayNamestring | null0.1.0
emailstring | null0.1.0
emailVerifiedboolean0.1.0
isAnonymousboolean0.1.0
metadataUserMetadataThe user's metadata.5.2.0
phoneNumberstring | null0.1.0
photoUrlstring | null0.1.0
providerDataUserInfo[]Additional per provider such as displayName and profile information.5.2.0
providerIdstring0.1.0
tenantIdstring | null0.1.0
uidstring0.1.0
UserMetadata
PropTypeDescriptionSince
creationTimenumberTime the user was created in milliseconds since the epoch.5.2.0
lastSignInTimenumberTime the user last signed in in milliseconds since the epoch.5.2.0
UserInfo
PropTypeDescriptionSince
displayNamestring | nullThe display name of the user.5.2.0
emailstring | nullThe email of the user.5.2.0
phoneNumberstring | nullThe phone number normalized based on the E.164 standard (e.g. +16505550101) for the user.5.2.0
photoUrlstring | nullThe profile photo URL of the user.5.2.0
providerIdstringThe provider used to authenticate the user.5.2.0
uidstringThe user's unique ID.5.2.0
AuthCredential
PropTypeDescriptionSince
accessTokenstringThe OAuth access token associated with the credential if it belongs to an OAuth provider.0.1.0
authorizationCodestringA token that the app uses to interact with the server. Only available for Apple Sign-in on iOS.1.2.0
idTokenstringThe OAuth ID token associated with the credential if it belongs to an OIDC provider.0.1.0
noncestringThe random string used to make sure that the ID token you get was granted specifically in response to your app's authentication request.0.1.0
providerIdstringThe authentication provider ID for the credential.0.1.0
secretstringThe OAuth access token secret associated with the credential if it belongs to an OAuth 1.0 provider.0.1.0
serverAuthCodestringThe server auth code. Only available for Google Sign-in and Play Games Sign-In on Android and iOS.5.2.0
AdditionalUserInfo
PropTypeDescriptionSince
isNewUserbooleanWhether the user is new (sign-up) or existing (sign-in).0.5.1
profile{ [key: string]: unknown; }Map containing IDP-specific user data.0.5.1
providerIdstringIdentifier for the provider used to authenticate this user.0.5.1
usernamestringThe username if the provider is GitHub or Twitter.0.5.1
ConfirmVerificationCodeOptions
PropTypeDescriptionSince
verificationIdstringThe verification ID received from the phoneCodeSent listener. The verificationCode option must also be provided.5.0.0
verificationCodestringThe verification code either received from the phoneCodeSent listener or entered by the user. The verificationId option must also be provided.5.0.0
CreateUserWithEmailAndPasswordOptions
PropTypeSince
emailstring0.2.2
passwordstring0.2.2
FetchSignInMethodsForEmailResult
PropTypeDescriptionSince
signInMethodsstring[]The sign-in methods for the specified email address. This list is empty when Email Enumeration Protection is enabled, irrespective of the number of authentication methods available for the given email.6.0.0
FetchSignInMethodsForEmailOptions
PropTypeDescriptionSince
emailstringThe user's email address.6.0.0
GetCurrentUserResult
PropTypeDescriptionSince
userUser | nullThe currently signed-in user, or null if there isn't any.0.1.0
GetIdTokenResult
PropTypeDescriptionSince
tokenstringThe Firebase Auth ID token JWT string.0.1.0
GetIdTokenOptions
PropTypeDescriptionSince
forceRefreshbooleanForce refresh regardless of token expiration.0.1.0
GetTenantIdResult
PropTypeDescriptionSince
tenantIdstring | nullThe tenant id. null if it has never been set.1.1.0
IsSignInWithEmailLinkResult
PropTypeDescription
isSignInWithEmailLinkbooleanWhether an incoming link is a signup with email link suitable for signInWithEmailLink(...).
IsSignInWithEmailLinkOptions
PropTypeDescriptionSince
emailLinkstringThe link sent to the user's email address.1.1.0
SignInWithOAuthOptions
PropTypeDescriptionDefaultSince
customParametersSignInCustomParameter[]Configures custom parameters to be passed to the identity provider during the OAuth sign-in flow. Supports Apple, Facebook, GitHub, Google, Microsoft, Twitter and Yahoo on Web. Supports Apple, GitHub, Microsoft, Twitter and Yahoo on Android. Supports Facebook, GitHub, Microsoft, Twitter and Yahoo on iOS.1.1.0
mode'popup' | 'redirect'Whether to use the popup-based OAuth authentication flow or the full-page redirect flow. If you choose redirect, you will get the result of the call via the authStateChange listener after the redirect. Only available for Web.'popup'1.3.0
scopesstring[]Scopes to request from provider. Supports Apple, Facebook, GitHub, Google, Microsoft, Twitter and Yahoo on Web. Supports Apple, GitHub, Google, Microsoft, Twitter, Yahoo and Play Games on Android. Supports Facebook, GitHub, Google, Microsoft, Twitter and Yahoo on iOS.1.1.0
SignInCustomParameter
PropTypeDescriptionSince
keystringThe custom parameter key (e.g. login_hint).0.1.0
valuestringThe custom parameter value (e.g. user@firstadd.onmicrosoft.com).0.1.0
LinkWithEmailAndPasswordOptions
PropTypeDescriptionSince
emailstringThe user's email address.1.1.0
passwordstringThe user's password.1.1.0
LinkWithEmailLinkOptions
PropTypeDescriptionSince
emailstringThe user's email address.1.1.0
emailLinkstringThe link sent to the user's email address.1.1.0
SignInWithOpenIdConnectOptions
PropTypeDescriptionSince
providerIdstringThe OpenID Connect provider ID.6.1.0
SignInWithPhoneNumberOptions
PropTypeDescriptionDefaultSince
phoneNumberstringThe phone number to be verified in E.164 format.0.1.0
recaptchaVerifierunknownThe reCAPTCHA verifier. Must be an instance of firebase.auth.RecaptchaVerifier. Only available for Web.5.2.0
resendCodebooleanResend the verification code to the specified phone number. signInWithPhoneNumber must be called once before using this option. Only available for Android.false1.3.0
timeoutnumberThe maximum amount of time in seconds to wait for the SMS auto-retrieval. Use 0 to disable SMS-auto-retrieval. Only available for Android.605.4.0
RevokeAccessTokenOptions
PropTypeDescriptionSince
tokenstringThe access token to revoke.6.1.0
SendEmailVerificationOptions
PropTypeDescriptionSince
actionCodeSettingsActionCodeSettingsStructure that contains the required continue/state URL with optional Android and iOS bundle identifiers.6.1.0
ActionCodeSettings

An interface that defines the required continue/state URL with optional Android and iOS bundle identifiers.

PropTypeDescription
android{ installApp?: boolean; minimumVersion?: string; packageName: string; }Sets the Android package name.
handleCodeInAppbooleanWhen set to true, the action code link will be be sent as a Universal Link or Android App Link and will be opened by the app if installed.
iOS{ bundleId: string; }Sets the iOS bundle ID.
urlstringSets the link continue/state URL.
dynamicLinkDomainstringWhen multiple custom dynamic link domains are defined for a project, specify which one to use when the link is to be opened via a specified mobile app (for example, example.page.link).
SendPasswordResetEmailOptions
PropTypeDescriptionSince
emailstring0.2.2
actionCodeSettingsActionCodeSettingsStructure that contains the required continue/state URL with optional Android and iOS bundle identifiers.6.1.0
SendSignInLinkToEmailOptions
PropTypeDescriptionSince
emailstringThe user's email address.1.1.0
actionCodeSettingsActionCodeSettingsStructure that contains the required continue/state URL with optional Android and iOS bundle identifiers.1.1.0
SetLanguageCodeOptions
PropTypeDescriptionSince
languageCodestringBCP 47 language code.0.1.0
SetPersistenceOptions
PropTypeDescriptionSince
persistencePersistenceThe persistence types.5.2.0
Persistence

An interface covering the possible persistence mechanism types.

PropTypeDescription
type'SESSION' | 'LOCAL' | 'NONE'Type of Persistence. - 'SESSION' is used for temporary persistence such as sessionStorage. - 'LOCAL' is used for long term persistence such as localStorage or IndexedDB. - 'NONE' is used for in-memory, or no persistence.
SetTenantIdOptions
PropTypeDescriptionSince
tenantIdstringThe tenant id.1.1.0
SignInWithCustomTokenOptions
PropTypeDescriptionSince
tokenstringThe custom token to sign in with.0.1.0
SignInWithEmailAndPasswordOptions
PropTypeDescriptionSince
emailstringThe user's email address.0.2.2
passwordstringThe user's password.0.2.2
SignInWithEmailLinkOptions
PropTypeDescriptionSince
emailstringThe user's email address.1.1.0
emailLinkstringThe link sent to the user's email address.1.1.0
SignInOptions
PropTypeDescriptionSince
skipNativeAuthbooleanWhether the plugin should skip the native authentication or not. Only needed if you want to use the Firebase JavaScript SDK. This value overwrites the configrations value of the skipNativeAuth option. If no value is set, the configuration value is used. Note that the plugin may behave differently across the platforms. skipNativeAuth cannot be used in combination with signInWithCustomToken, createUserWithEmailAndPassword or signInWithEmailAndPassword. Only available for Android and iOS.1.1.0
UnlinkResult
PropTypeDescriptionSince
userUser | nullThe currently signed-in user, or null if there isn't any.1.1.0
UnlinkOptions
PropTypeDescriptionSince
providerIdProviderIdThe provider to unlink.1.1.0
UpdateEmailOptions
PropTypeDescriptionSince
newEmailstringThe new email address.0.2.2
UpdatePasswordOptions
PropTypeDescriptionSince
newPasswordstringThe new password.0.2.2
UpdateProfileOptions
PropTypeDescriptionSince
displayNamestring | nullThe user's display name.1.3.0
photoUrlstring | nullThe user's photo URL.1.3.0
UseEmulatorOptions
PropTypeDescriptionDefaultSince
hoststringThe emulator host without any port or scheme.0.2.0
portnumberThe emulator port.90990.2.0
schemestringThe emulator scheme. Only available for Web."http"5.2.0
PluginListenerHandle
PropType
remove() => Promise<void>
AuthStateChange
PropTypeDescriptionSince
userUser | nullThe currently signed-in user, or null if there isn't any.0.1.0
PhoneVerificationCompletedEvent
PropTypeDescriptionSince
verificationCodestringThe verification code sent to the user's phone number. If instant verification is used, this property is not set.5.0.0
PhoneVerificationFailedEvent
PropTypeDescriptionSince
messagestringThe error message.1.3.0
PhoneCodeSentEvent
PropTypeDescriptionSince
verificationIdstringThe verification ID, which is needed to identify the verification code.1.3.0

Type Aliases

LinkWithOAuthOptions

SignInWithOAuthOptions

LinkResult

SignInResult

LinkWithOpenIdConnectOptions

SignInWithOpenIdConnectOptions

LinkWithPhoneNumberOptions

SignInWithPhoneNumberOptions

AuthStateChangeListener

Callback to receive the user's sign-in state change notifications.

(change: AuthStateChange): void

PhoneVerificationCompletedListener

Callback to receive the verification code sent to the user's phone number.

(event: PhoneVerificationCompletedEvent): void

PhoneVerificationFailedListener

Callback to receive notifications of failed phone verification.

(event: PhoneVerificationFailedEvent): void

PhoneCodeSentListener

Callback to receive the verification ID.

(event: PhoneCodeSentEvent): void

Enums

Persistence
MembersValueDescriptionSince
IndexedDbLocal'INDEXED_DB_LOCAL'Long term persistence using IndexedDB.5.2.0
InMemory'IN_MEMORY'No persistence.5.2.0
BrowserLocal'BROWSER_LOCAL'Long term persistence using local storage.5.2.0
BrowserSession'BROWSER_SESSION'Temporary persistence using session storage.5.2.0
ProviderId
MembersValue
APPLE'apple.com'
FACEBOOK'facebook.com'
GAME_CENTER'gc.apple.com'
GITHUB'github.com'
GOOGLE'google.com'
MICROSOFT'microsoft.com'
PLAY_GAMES'playgames.google.com'
TWITTER'twitter.com'
YAHOO'yahoo.com'
PASSWORD'password'
PHONE'phone'

Changelog

See CHANGELOG.md.

License

See LICENSE.

Credits

This plugin is based on the Capacitor Firebase Authentication plugin. Thanks to everyone who contributed to the project!

Footnotes

  1. This project is not affiliated with, endorsed by, sponsored by, or approved by Google LLC or any of their affiliates or subsidiaries.

Keywords

FAQs

Package last updated on 21 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc