我如何通过react + firebase使用获取令牌?

时间:2019-01-30 19:43:28

标签: javascript reactjs firebase-realtime-database firebase-authentication redux-saga

export function* login(auth, action){
try{
    const {signInWithEmailAndPassword} = auth
    const {email, password} = action.user
    const user = yield call([auth, signInWithEmailAndPassword], email, password)
    const {ra} = user.user
    yield auth.verifyIdToken(ra)
        .then(function(decodedToken) {
            let uid = decodedToken.uid
            console.log(uid)
        }).catch(function(error) {
            console.log('error no token')
        })
    /*
    axios.post('/api/token', { i really need to call a cloud function?
        ra
    }).then(data => data.data)
    */
    yield put(ActionCreator.signinSuccess(user.user))
}catch({message}){
    yield put(ActionCreator.signinFailure("Dind't have possible do login"))
}        
}

我的疑问是:当我登录到Firebase时,我得到一个令牌,该令牌保留在变量“ user.user.ra”中。为了能够在对Firebase实时数据库的请求中使用此令牌,我是否需要将该令牌发送到云函数以进行验证,还是可以自己使用某种方法来执行此操作?在firebase网站中,您可以使用方法admin.auth().VerifyIdToken(idToken)进行此验证,但是我无法在其中使用它。我该怎么办?

0 个答案:

没有答案