LoginSignup
2
1

More than 1 year has passed since last update.

【Typescript】FirebaseのGoogle認証を使用して、ユーザー情報を取得する

Posted at

async login () {
  try {
    const res = await auth.signInWithPopup(provider)

    //  Property 'email' does not exist on type 'Object'.
    const email = res.additionalUserInfo.profile.email
  }
}

上記のようにfirebaseで用意されているsignInWithPopup()を使用して、返り値であるユーザー情報を状態管理ライブラリに持たせようとしたら、型定義エラーが起きてずっとハマっていました。

解決法

auth.currentUserで現在ログイン中のユーザー情報を取得できる


async login () {
  try {
    await auth.signInWithPopup(provider)

    this.email = auth.currentUser?.email
    this.name = auth.currentUser?.displayName
  } catch (e) {
    throw new Error('ログインに失敗 ')
  }
}
2
1
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
2
1