问题
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