LoginSignup
1
0

More than 3 years have passed since last update.

Property 'accessToken' does not exist on type 'AuthCredential'の解決方法

Posted at

FirebaseでgetRedirectResultのレスポンスを扱う際に型のエラーが発生しました。

firebase
  .auth()
  .getRedirectResult()
  .then((result) => {
    const credential = result.credential
    console.log(credential.accessToken) // ここでエラーが発生する
  })

この状態だと以下のエラーが発生する

Property 'accessToken' does not exist on type 'AuthCredential'.Vetur(2339)

accessTokenプロパティがAuthCredentialオブジェクトに存在していないようです。

対策

AuthCredentialにOAuthCredential持つaccessTokenプロパティをキャストする必要があります。
https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth-types/index.d.ts#L244

firebase
  .auth()
  .getRedirectResult()
  .then((result) => {
    const credential = result.credential as firebase.auth.OAuthCredential
    console.log(credential.accessToken) //  エラーは発生しない
  })

const credential = result.credential
この部分を
const credential = result.credential as firebase.auth.OAuthCredential
こんな感じにする

参考記事

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