Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}).then(async(res) => {
if (!res.IsSuccess) {
return reject(new Error('Cant login with facebook right now!'));
}
// Set token in AsyncStorage + memory
await AsyncStorage.setItem('api/token', res.Token);
// Get user details from API, using user token
return AppAPI.connect.get()
.then(async(userData) => {
dispatch({
type: 'USER_REPLACE',
data: userData
});
return resolve(userData);
}).catch(err => reject(err));
}).catch(err => reject(err));
} else {
storeData = () => {
AsyncStorage.setItem(STORAGE_KEY, DATA)
.then(() => {
console.log('data stored..');
});
}
setAccessToken: async (token) => {
AsyncStorage.setItem(Constants.IDENTIFIERS.ACCESS_TOKEN, token);
},
alarm.notificationTime = scheduleAlarm(alarm);
} else {
alarm.on = false;
alarm.notificationTime = null;
}
}
return alarm;
});
}
if (activeAlarm === null) {
SplashScreen.hide();
}
try {
AsyncStorage.setItem('alarms', JSON.stringify(alarms));
return dispatch(loadAlarmsSuccess(alarms, activeAlarm));
} catch (error) {
return null;
}
};
}
}
if (stateVar === "healthTips") {
if (!this.state.healthTips) {
await AsyncStorage.setItem("health_tips", "true");
this.setState({ healthTips: !this.state.healthTips });
} else {
await AsyncStorage.setItem("health_tips", "false");
this.setState({ healthTips: !this.state.healthTips });
}
}
if (stateVar === "transpoTips") {
if (!this.state.transpoTips) {
await AsyncStorage.setItem("transpo_tips", "true");
this.setState({ transpoTips: !this.state.transpoTips });
} else {
await AsyncStorage.setItem("transpo_tips", "false");
this.setState({ transpoTips: !this.state.transpoTips });
}
}
if (stateVar === "financialTips") {
if (!this.state.financialTips) {
await AsyncStorage.setItem("financial_tips", "true");
this.setState({ financialTips: !this.state.financialTips });
} else {
await AsyncStorage.setItem("financial_tips", "false");
this.setState({ financialTips: !this.state.financialTips });
}
}
};
} else {
localStorage[key] = json;
}
}
} else {
if (User.secureKeys.has(key)) {
if (noValue) {
SecureStore.deleteItemAsync(key);
} else {
SecureStore.setItemAsync(key, json);
}
} else if (User.persistedKeys.has(key)) {
if (noValue) {
AsyncStorage.removeItem(key);
} else {
AsyncStorage.setItem(key, json);
}
}
}
});
async persistVariant({ variant, component }) {
await AsyncStorage.setItem(`${LOCAL_STORAGE_KEY}-${experiment}`, variant);
this.props.onVariantSelect(variant);
return this.setState({ variant, component });
}
saveState(callback) {
AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(this.state), (err) => {
if (err) {
throw err;
}
if (callback) callback();
});
}
const user = firebase.auth().currentUser;
if (!user) {
return null;
}
if (user.email) {
await AsyncStorage.setItem('email', user.email);
await AsyncStorage.setItem('uid', user.uid);
setState({
email: user.email,
uid: user.uid,
});
}
const idToken = await user.getIdToken(refresh);
await AsyncStorage.setItem('id_token', idToken);
await AsyncStorage.setItem(
'expiration',
String(new Date().getTime() + 60 * 60)
);
return idToken;
}, []);
async onSuccess(data) {
try {
await AsyncStorage.setItem(key, JSON.stringify(data));
} catch (error) {
ToastAndroid.show(String(error).replace('Error: ',''), ToastAndroid.LONG);
}
}