How do I get the current user's access token in AngularFire2?

后端 未结 7 2194
星月不相逢
星月不相逢 2021-02-08 11:10

In AngularFire you were able to access the providers (e.g Google) accessToken for the authenticated user.

There does not seem to be a way to access this with AngularFire

相关标签:
7条回答
  • 2021-02-08 11:41

    With AngularFire2 : ( eg : registering user with email and password combo. )

    import { AngularFireAuth } from 'angularfire2/auth';
    model : any = {} ;
    private afAuth : AngularFireAuth,
    
    regWithEP () {
        this.afAuth.auth.createUserWithEmailAndPassword(this.model.email, this.model.password).then((user) => {
        /* IMPORTANT !! */
        /* EXPLICIT CHECK IF USER IS RETURNED FROM FIREBASE SERVICE !! */
    
              if (user) {
                console.log(user);
                /* Here user is available and is the same as auth.currentUser */
    
                this.afAuth.auth.currentUser.getToken().then((token) => {
    
                //token is available here
                //set token to currentUser, signIn , re-direct etc.
                });
            }
        });
    }
    
    0 讨论(0)
提交回复
热议问题