New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

@vojto/capacitor-firebase-authentication

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vojto/capacitor-firebase-authentication

Capacitor plugin for Firebase Authentication.

latest
Source
npmnpm
Version
0.3.5
Version published
Maintainers
1
Created
Source


Firebase Authentication

@robingenz/capacitor-firebase-authentication

Capacitor plugin for Firebase Authentication.


About

This plugin is an implementation of Firebase Auth using the native Firebase SDK for Java (Android) and Swift (iOS). When using this plugin the user will be authenticated into the native layer. This means that you can use other native plugins that require authenticated firebase users.

If you also want to use the Firebase JS SDK in your app, you will need to make sure that the web layer also gets authenticated. This is not yet built into this plugin by default. See #41 for more information on this.

Maintainers

MaintainerGitHubSocial
Robin Genzrobingenz@robin_genz

Installation

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

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

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)
}

The further installation steps depend on the selected authentication method:

Configuration

No configuration required for this plugin.

Usage

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

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

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

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

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

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

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

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

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

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

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

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

API

getCurrentUser()

getCurrentUser() => Promise<GetCurrentUserResult>

Fetches the currently signed-in user.

Only available for Android and iOS.

Returns: Promise<GetCurrentUserResult>

getIdToken(...)

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

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

Only available for Android and iOS.

ParamType
optionsGetIdTokenOptions

Returns: Promise<GetIdTokenResult>

setLanguageCode(...)

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

Sets the user-facing language code for auth operations.

ParamType
optionsSetLanguageCodeOptions

signInWithApple()

signInWithApple() => Promise<SignInResult>

Starts the Apple sign-in flow.

Only available for Android and iOS.

Returns: Promise<SignInResult>

signInWithGithub()

signInWithGithub() => Promise<SignInResult>

Starts the GitHub sign-in flow.

Only available for Android and iOS.

Returns: Promise<SignInResult>

signInWithGoogle()

signInWithGoogle() => Promise<SignInResult>

Starts the Google sign-in flow.

Only available for Android and iOS.

Returns: Promise<SignInResult>

signInWithMicrosoft()

signInWithMicrosoft() => Promise<SignInResult>

Starts the Microsoft sign-in flow.

Only available for Android and iOS.

Returns: Promise<SignInResult>

signInWithTwitter()

signInWithTwitter() => Promise<SignInResult>

Starts the Twitter sign-in flow.

Only available for Android and iOS.

Returns: Promise<SignInResult>

signInWithYahoo()

signInWithYahoo() => Promise<SignInResult>

Starts the Yahoo sign-in flow.

Only available for Android and iOS.

Returns: Promise<SignInResult>

signOut()

signOut() => Promise<void>

Starts the sign-out flow.

Only available for Android and iOS.

useAppLanguage()

useAppLanguage() => Promise<void>

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

Interfaces

GetCurrentUserResult

PropTypeDescription
userUser | nullThe currently signed-in user, or null if there isn't any.

User

PropType
displayNamestring | null
emailstring | null
emailVerifiedboolean
isAnonymousboolean
phoneNumberstring | null
photoUrlstring | null
providerIdstring
tenantIdstring | null
uidstring

GetIdTokenResult

PropTypeDescription
tokenstringThe Firebase Auth ID token JWT string.

GetIdTokenOptions

PropTypeDescription
forceRefreshbooleanForce refresh regardless of token expiration.

SetLanguageCodeOptions

PropTypeDescription
languageCodestringBCP 47 language code. Example: en-US.

SignInResult

PropTypeDescription
userUser | nullThe currently signed-in user, or null if there isn't any.
idTokenstring | null
rawNoncestring | null
accessTokenstring | null

Changelog

See CHANGELOG.md.

License

See LICENSE.

Keywords

capacitor

FAQs

Package last updated on 22 Jul 2021

Related posts