Firebase getIdToken returns object

别说谁变了你拦得住时间么 提交于 2021-02-07 08:17:28

问题


I am using redux-saga and redux-saga-firebase library to integrate firebase with redux-sagas. The problem is when I sign in a user, for example with signInWithEmailAndPassword and even connect channel to get the signed user and track user changes, I am not able to get correct token. getIdToken, getIdTokenResult methods just return objects with the following representation:

{
    a: 0
    b: qb {a: null, g: ƒ, b: ƒ, f: undefined, next: null, …}
    c: A {a: 0, i: undefined, c: A, b: qb, f: qb, …}
    f: qb {a: null, g: ƒ, b: ƒ, f: undefined, next: null, …}
    g: false
    h: false
    i: undefined
}

And here is the code:

function* loginSaga({ payload: { email, password } }) {
    try {
        yield call(
            reduxSagaFirebase.auth.signInWithEmailAndPassword,
            email,
            password,
        );
    } catch (error) {
        yield put(loginFailure(error));
    }
}

function* loginStatusWatcher() {
    const channel = yield call(reduxSagaFirebase.auth.channel);

    while (true) {
        const { user } = yield take(channel);
        if (user) {
            yield put(loginSuccess());
        } else {
            console.log('Put logout action here');
        }
    }
}

What am I doing wrong?


回答1:


getIdToken returns a promise, make sure you use getIdToken().then((token) => console.log(token))



来源:https://stackoverflow.com/questions/53881916/firebase-getidtoken-returns-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!