Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const decodedRefreshToken = jwtDecode(refreshToken);
const currentTime = Date.now() / 1000;
if (decodedToken.exp >= currentTime || decodedRefreshToken.exp >= currentTime) {
// Token valid
return {
headers: {
...headers,
'x-token': token,
'x-refresh-token': refreshToken,
},
};
}
}
// No (valid) Token present - login
const deviceHash = await sha256(DeviceInfo.getUniqueID());
const phoneHash = await AsyncStorage.getItem('auth_phoneHash');
const newHeaders = {
...headers,
'x-device-hash': deviceHash,
};
if (phoneHash) {
newHeaders['x-phone-hash'] = phoneHash;
}
return { headers: newHeaders };
});
onChangeCode = async code => {
if (code.length === 6) {
const phoneNumber = await AsyncStorage.getItem('auth_phone');
const phoneNumberHash = await sha256(phoneNumber);
const res = await this.props.requestVerification({
variables: { code, newPhoneHash: phoneNumberHash },
});
if (res.data.requestVerification.succeeded) {
AsyncStorage.setItem('auth_phoneHash', phoneNumberHash);
Keyboard.dismiss();
this.props.navigator.push({
screen: 'democracy.SmsVerification.Success',
backButtonTitle: 'Zurück',
passProps: {
onComplete: this.props.onComplete,
},
navigatorStyle: { navBarHidden: true },
});
} else {
this.showNotification({ message: res.data.requestVerification.reason });