@robingenz/capacitor-firebase-authentication
Capacitor plugin for Firebase Authentication.
Maintainer | GitHub | Social |
---|---|---|
Robin Genz | robingenz | @robin_genz |
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:
These configuration values are available:
Prop | Type | Description | Default |
---|---|---|---|
skipNativeAuth |
boolean |
Configure whether the plugin should skip the native authentication. Only needed if you want to use the Firebase JavaScript SDK. Only available for Android and iOS. | false |
In capacitor.config.json
:
{
"plugins": {
"FirebaseAuthentication": {
"skipNativeAuth": false
}
}
}
In capacitor.config.ts
:
/// <reference types="@capacitor/firebase-authentication" />
import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
plugins: {
FirebaseAuthentication: {
skipNativeAuth: false,
},
},
};
export default config;
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();
};
getCurrentUser()
getIdToken(...)
setLanguageCode(...)
signInWithApple()
signInWithGithub()
signInWithGoogle()
signInWithMicrosoft()
signInWithTwitter()
signInWithYahoo()
signOut()
useAppLanguage()
- Interfaces
getCurrentUser() => Promise<GetCurrentUserResult>
Fetches the currently signed-in user.
Only available for Android and iOS.
Returns: Promise<GetCurrentUserResult>
getIdToken(options?: GetIdTokenOptions | undefined) => Promise<GetIdTokenResult>
Fetches the Firebase Auth ID Token for the currently signed-in user.
Only available for Android and iOS.
Param | Type |
---|---|
options |
GetIdTokenOptions |
Returns: Promise<GetIdTokenResult>
setLanguageCode(options: SetLanguageCodeOptions) => Promise<void>
Sets the user-facing language code for auth operations.
Param | Type |
---|---|
options |
SetLanguageCodeOptions |
signInWithApple() => Promise<SignInResult>
Starts the Apple sign-in flow.
Only available for Android and iOS.
Returns: Promise<SignInResult>
signInWithGithub() => Promise<SignInResult>
Starts the GitHub sign-in flow.
Only available for Android and iOS.
Returns: Promise<SignInResult>
signInWithGoogle() => Promise<SignInResult>
Starts the Google sign-in flow.
Only available for Android and iOS.
Returns: Promise<SignInResult>
signInWithMicrosoft() => Promise<SignInResult>
Starts the Microsoft sign-in flow.
Only available for Android and iOS.
Returns: Promise<SignInResult>
signInWithTwitter() => Promise<SignInResult>
Starts the Twitter sign-in flow.
Only available for Android and iOS.
Returns: Promise<SignInResult>
signInWithYahoo() => Promise<SignInResult>
Starts the Yahoo sign-in flow.
Only available for Android and iOS.
Returns: Promise<SignInResult>
signOut() => Promise<void>
Starts the sign-out flow.
Only available for Android and iOS.
useAppLanguage() => Promise<void>
Sets the user-facing language code to be the default app language.
Prop | Type | Description |
---|---|---|
user |
User | null |
The currently signed-in user, or null if there isn't any. |
Prop | Type |
---|---|
displayName |
string | null |
email |
string | null |
emailVerified |
boolean |
isAnonymous |
boolean |
phoneNumber |
string | null |
photoUrl |
string | null |
providerId |
string |
tenantId |
string | null |
uid |
string |
Prop | Type | Description |
---|---|---|
token |
string |
The Firebase Auth ID token JWT string. |
Prop | Type | Description |
---|---|---|
forceRefresh |
boolean |
Force refresh regardless of token expiration. |
Prop | Type | Description |
---|---|---|
languageCode |
string |
BCP 47 language code. Example: en-US . |
Prop | Type | Description |
---|---|---|
user |
User | null |
The currently signed-in user, or null if there isn't any. |
credential |
AuthCredential | null |
Credentials returned by an auth provider. |
Prop | Type | Description |
---|---|---|
providerId |
string |
The authentication provider ID for the credential. For example, 'google.com'. |
accessToken |
string |
The OAuth access token associated with the credential if it belongs to an OAuth provider. |
idToken |
string |
The OAuth ID token associated with the credential if it belongs to an OIDC provider. |
secret |
string |
The OAuth access token secret associated with the credential if it belongs to an OAuth 1.0 provider. |
nonce |
string |
The random string used to make sure that the ID token you get was granted specifically in response to your app's authentication request. |
- What does this plugin do?
This plugin enables the use of Firebase Authentication in a Capacitor app. It uses the native Firebase SDK for Java (Android) and Swift (iOS). Accordingly, the plugin signs the user in at the native layer of the app. The Firebase JavaScript SDK is not required, but can be used. - Which platforms are supported?
Currently, only Android and iOS are supported. It is planned to support web soon as well (see #20). In the meantime, the Firebase JavaScript SDK can be used. - How can I use this plugin with the Firebase JavaScript SDK?
See here.
See CHANGELOG.md.
See LICENSE.