【问题标题】:Firebase getIdToken returns objectFirebase getIdToken 返回对象
【发布时间】:2019-05-21 18:09:39
【问题描述】:

我正在使用redux-sagaredux-saga-firebase 库将firebase 与redux-sagas 集成。问题是当我登录用户时,例如使用signInWithEmailAndPassword 甚至连接channel 以获取签名用户并跟踪用户更改,我无法获得正确的令牌。 getIdTokengetIdTokenResult 方法只返回具有以下表示的对象:

{
    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
}

这里是代码:

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');
        }
    }
}

我做错了什么?

【问题讨论】:

  • 这个问题你解决了吗?我有同样的问题。

标签: javascript firebase firebase-authentication redux-saga


【解决方案1】:

getIdToken 返回一个承诺,确保你使用getIdToken().then((token) => console.log(token))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 2018-09-18
    • 1970-01-01
    • 2018-11-14
    • 2017-08-25
    • 2017-06-13
    • 1970-01-01
    相关资源
    最近更新 更多