Reputation: 813
My code is the following. I get undefined is not a function (evaluating '_this.storeAPIToken(responseJson.APIToken)') error
async function storeAPIToken(APIToken) {
try {
await AsyncStorage.setItem('@auth:APIToken', APIToken);
} catch (error) {
console.log("STORE API", error);
}
}
const verifyOTPResponse = (dispatch, responseJson) => {
console.log("checkOTPAPIStatus", responseJson.status);
if (responseJson.status == "OK") {
console.log("verifyOTPEntered OK");
console.log('Token', responseJson.APIToken);
this.storeAPIToken(responseJson.APIToken);
firebase.auth().signInWithCustomToken(responseJson.token).then(() => {
console.log("Login successfulx");
dispatch({
type: types.LOGIN_SUCCESS,
payload: 1
});
}).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
dispatch({
type: types.LOGIN_FAIL,
payload: 0
});
});
} else {
dispatch({
type: types.OTP_VERIFICATION_FAIL,
payload: loginStatus
});
The responseJson.APIToken is not null it has value when I console logged it
Upvotes: 0
Views: 772
Reputation: 1518
Remove this.
from the line calling this.storeAPIToken(responseJson.APIToken);
. this context that refers at that line is different from the one to storeAPIToken
.
Upvotes: 1