代码之家  ›  专栏  ›  技术社区  ›  Sireini

属性“Access”不存在于“凭据”类型上。

  •  2
  • Sireini  · 技术社区  · 6 年前

    通过运行ionic serve,我得到以下错误:

    Property 'accessToken' does not exist on type 'AuthCredential'.
    // You can use it to access the Google API.
    let token = result.credential.accessToken;
    

    我已经更新了我的firebase firebase: ^4.12.1 firebase: ^5.5.9

    这是我的离子信息输出

    Ionic:
    
       ionic (Ionic CLI)  : 4.1.2
       Ionic Framework    : ionic-angular 3.9.2
       @ionic/app-scripts : 3.1.9
    
    Cordova:
    
       cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
       Cordova Platforms     : android 7.0.0
       Cordova Plugins       : no whitelisted plugins (19 plugins total)
    
    System:
    
       NodeJS : v10.13.0 (C:\Program Files\nodejs\node.exe)
       npm    : 5.8.0
       OS     : Windows 10
    

    这就是 auth.service.ts

    signInWithGoogle() {
       console.log('Sign in with google');
       return this.oauthSignIn(new firebase.auth.GoogleAuthProvider());
    }
    
    private oauthSignIn(provider: AuthProvider) {
       if (!(<any>window).cordova) {
            return this.afAuth.auth.signInWithPopup(provider).then(() => {
                this.saveUserDetails('gmail');
            });
       } else {
           return this.afAuth.auth.signInWithRedirect(provider)
               .then(() => {
                  return this.afAuth.auth.getRedirectResult().then(result => {
                     // This gives you a Google Access Token.
                    // You can use it to access the Google API.
                    let token = result.credential.accessToken;
                   // The signed-in user info.
                    let result_user = result.user;
    
                    this.saveUserDetails('gmail');
    
                    console.log(token, result_user);
          }).catch(function (error) {
             // Handle Errors here.
             alert(error.message);
          });
       });
      }
    }
    

    为什么AuffToSKEN属性不存在于AuthCudio对象上?

    2 回复  |  直到 6 年前
        1
  •  6
  •   bojeil    6 年前

    你需要把 AuthCredential OAuthCredential 其中有 accessToken 属性: https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth-types/index.d.ts#L244

        2
  •  1
  •   dimvar    6 年前

    您需要查看AuthCredential的定义。如果是 this one ,它没有accessToken属性。

        3
  •  1
  •   dxt    5 年前

    由于类型脚本定义而发生错误

    替换

    let token = result.credential.accessToken;

    具有

    let token = (<any>result).credential.accessToken;