1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Flutter】FirebaseのlinkWithPopupについて調べてみた

Posted at

注意点
調べた限りだと、iOSとAndroidは対応されていないらしいです。
別の実装方法を近いうちに共有できればなと思っています。

linkWithPopupとは

  • 既存のユーザー アカウントに認証プロバイダの認証情報をリンクすると、ユーザーが複数の認証プロバイダを使用してアプリにログインできる
  • ログインに使用した認証プロバイダに関係なく、同じ Firebase ユーザー ID でユーザーを識別できる

具体例

  • あるアプリをGoogleアカウントでログインして、その後に、Facebookアカウントでも同じアカウントにログインができる
  • そして、Googleアカウントでログインした場合でも、Facebookアカウントでログインした場合でも、FirebaseのユーザーIDは同じままになる

実装例

Firebaseのセットアップについては割愛させていただきます。詳しくはこちら↓

[✓] Flutter (Channel stable, 3.16.5, on macOS 14.0 23A344 darwin-arm64, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.87.2)
[✓] Connected device (4 available)
[✓] Network resources
  • 使用するPackages
dependencies:
  firebase_auth: ^4.17.4
  firebase_core: ^2.27.0

1. linkWithPopupを使うための Auth Providerを記載

final twitter = TwitterAuthProvider();
final google = GoogleAuthProvider();
final facebook = FacebookAuthProvider();
final github = GithubAuthProvider();

2. linkWithPopupを呼び出す

Future<void> twitterLinkWithPopup() async {
  final currentUser = firebase.currentUser;
   if (currentUser == null) {
      return;
    }
  await currentUser.linkWithPopup(provider);
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?