ガイド
Capacitor で Firebase Authentication を使う方法
@capgo/capacitor-firebase-authentication の使い方
Firebase Authentication 用の Capacitor プラグイン
インストール
bun add @capgo/capacitor-firebase-authentication
bunx cap sync
bunx cap sync プラグインのネイティブ code をネイティブプロジェクトにコピーします。プラグインをアップグレードするたびに再度実行してください。
インポート
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
API の概要
| メソッド | 説明 |
|---|---|
applyActionCode |
ユーザーにメールで送信された code を検証します。 |
confirmPasswordReset |
パスワードリセット処理を完了します。 |
confirmVerificationCode |
電話番号の認証プロセスを完了します。 |
createUserWithEmailAndPassword |
メールアドレスとパスワードで新しいユーザーアカウントを作成します。アカウント作成後、自動的にサインインされます。 |
deleteUser |
ユーザーを削除し、サインアウトします。 |
fetchSignInMethodsForEmail |
メールアドレスに対応するサインイン方法を取得します。 |
getCurrentUser |
現在サインインしているユーザーを取得します。 |
getPendingAuthResult |
を返します SignInResult アプリがWebサインインフローを開始し、バックグラウンド中にOSがアプリを終了した場合。 |
getIdToken |
現在サインインしているユーザーの Firebase Auth ID Token を取得します。 |
getIdTokenResult |
Firebase サービスでユーザーを識別するために使用される、デシリアライズされた JSON Web Token (JWT) を返します。 |
getRedirectResult |
を返します SignInResult リダイレクトベースのサインインフローから取得します。 |
getTenantId |
テナント ID を取得します。 |
isSignInWithEmailLink |
受信したリンクが、以下の用途に適したメールリンクによるサインインであるかを確認します。 signInWithEmailLink. |
linkWithApple |
ユーザーアカウントを Apple 認証プロバイダーに連携します。 |
linkWithEmailAndPassword |
ユーザーアカウントをメール認証プロバイダーにリンクします。 |
linkWithEmailLink |
ユーザーアカウントをメール認証プロバイダーにリンクします。 |
linkWithFacebook |
ユーザーアカウントを Facebook 認証プロバイダーに連携します。 |
linkWithGameCenter |
ユーザーアカウントを Game Center 認証プロバイダーと連携させます。 |
linkWithGithub |
ユーザーアカウントを GitHub 認証プロバイダーと連携させます。 |
linkWithGoogle |
ユーザーアカウントを Google 認証プロバイダーと連携させます。 |
linkWithMicrosoft |
ユーザーアカウントを Microsoft 認証プロバイダーと連携させます。 |
linkWithOpenIdConnect |
ユーザーアカウントを OpenID Connect プロバイダーと連携させます。 |
linkWithPhoneNumber |
ユーザーアカウントを電話番号認証プロバイダーと連携させます。 |
linkWithPlayGames |
ユーザーアカウントを Play Games 認証プロバイダーと連携させます。 |
linkWithTwitter |
ユーザーアカウントを Twitter 認証プロバイダーと連携させます。 |
linkWithYahoo |
ユーザーアカウントを Yahoo 認証プロバイダーと連携させます。 |
reload |
サインイン済みの場合、ユーザーアカウントのデータをリロードします。 |
revokeAccessToken |
指定されたアクセストークンを無効化します。現在は Apple OAuth アクセストークンのみをサポートしています。 |
sendEmailVerification |
現在サインインしているユーザーに確認メールを送信します。 |
sendPasswordResetEmail |
パスワードリセットメールを送信します。 |
sendSignInLinkToEmail |
指定されたメールアドレス宛にサインイン用リンクを送信します。 |
setLanguageCode |
認証操作で使用するユーザー向け言語 code を設定します。 |
setPersistence |
保存されている認証セッションの永続化タイプを設定します。 |
setTenantId |
テナントIDを設定します。 |
signInAnonymously |
匿名ユーザーとしてサインインします。 |
signInWithApple |
Appleでのサインインフローを開始します。 |
signInWithCustomToken |
カスタムトークンによるサインインフローを開始します。 |
signInWithEmailAndPassword |
メールアドレスとパスワードによるサインインフローを開始します。 |
signInWithEmailLink |
メールアドレスとサインイン用リンクを使用してサインインします。 |
signInWithFacebook |
Facebookでのサインインフローを開始します。 |
signInWithGameCenter |
Game Centerでのサインインフローを開始します。 |
signInWithGithub |
GitHub のサインインフローを開始します。 |
signInWithGoogle |
Google のサインインフローを開始します。 |
signInWithMicrosoft |
Microsoft のサインインフローを開始します。 |
signInWithOpenIdConnect |
OpenID Connect のサインインフローを開始します。 |
signInWithPhoneNumber |
電話番号を使用したサインインフローを開始します。 |
signInWithPlayGames |
Play Games のサインインフローを開始します。 |
signInWithTwitter |
Twitter のサインインフローを開始します。 |
signInWithYahoo |
Yahoo のサインインフローを開始します。 |
signOut |
サインアウトフローを開始します。 |
unlink |
ユーザーアカウントからプロバイダーの連携を解除します。 |
updateEmail |
ログイン中のユーザーのメールアドレスを更新します。 |
updatePassword |
ログイン中のユーザーのパスワードを更新します。 |
updateProfile |
ユーザーのプロフィールデータを更新します。 |
useAppLanguage |
ユーザー向けの言語 code をアプリのデフォルト言語として設定します。 |
useEmulator |
Authentication エミュレータと通信するようにアプリを構成します。 |
verifyBeforeUpdateEmail |
ログイン中のユーザーのメールアドレスを更新する前に、新しいメールアドレスの検証を行います。 |
checkAppTrackingTransparencyPermission |
App Tracking Transparency の現在のステータスを確認します。 |
requestAppTrackingTransparencyPermission |
App Tracking Transparency の許可を求めるシステムダイアログを表示します。 |
実装例
applyActionCode()
メールでユーザーに送信された検証用 code を適用します。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.applyActionCode({ oobCode: 'oob-code' });
confirmPasswordReset()
パスワードリセット処理を完了します。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.confirmPasswordReset({
oobCode: 'oob-code',
newPassword: 'new-password',
});
confirmVerificationCode()
電話番号の検証プロセスを完了します。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.confirmVerificationCode({
verificationId: 'phoneCodeSent',
verificationCode: 'phoneCodeSent',
});
// The result holds sensitive values: use it without logging it.
createUserWithEmailAndPassword()
メールアドレスとパスワードを使用して新しいユーザーアカウントを作成します。アカウント作成後、自動的にサインインされます。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.createUserWithEmailAndPassword({
email: 'user@example.com',
password: 'password',
});
// The result holds sensitive values: use it without logging it.
deleteUser()
ユーザーを削除し、サインアウトします。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.deleteUser();
fetchSignInMethodsForEmail()
メールアドレスに対応するサインイン方法を取得します。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.fetchSignInMethodsForEmail({ email: 'user@example.com' });
console.log(result);
上記の表には59個のコアメソッドが記載されています。リスナーやバージョンのヘルパー、各メソッドの詳細な仕様については、 GitHub リポジトリ.
イベントをリッスンする
addListener ハンドルを返します。次に、 handle.remove() 画面がアンマウントされるとき、または FirebaseAuthentication.removeAllListeners() すべてのリスナーを解除します。
リファレンス全文
次は @capgo/capacitor-firebase-authentication の使用方法へ
以下を使用している場合: @capgo/capacitor-firebase-authentication の使い方 認証とアカウントフローを計画するには、以下と連携させてください @capgo/capacitor-social-login @capgo/capacitor-social-login の実装詳細については、 @capgo/capacitor-passkey @capgo/capacitor-passkey の実装詳細については、 @capgo/capacitor-native-biometric @capgo/capacitor-native-biometric の実装詳細については、 二要素認証 2要素認証の実装詳細については、 SSO (エンタープライズ) SSO (Enterprise) の実装詳細については、