I have react-native/graphql/apollo app. The user makes the request to get credentials from the server and after they are written to Keychain by async/await. If it success the user have to navigate from Auth to Home screen. I use .then for the navigation after Keychain async/await. Can somebody tell me is it a good way or i don't need to use .then?
const AuthScreen = ({ navigation }) => {
const sign = useMutation(SIGN_IN)
const handleSignIn = code => {
sign({
variables: { code },
update: async (cache, { data }) => {
const accessToken = data.signIn.accessToken
const refreshToken = data.signIn.refreshToken
await Keychain.setGenericPassword(accessToken, refreshToken)
}
}).then(() => navigation.navigate('Home'))
}
const getToken = async () => {
// setLoading(true)
RNAccountKit.configure({
responseType: 'code',
initialPhoneCountryPrefix: '+7',
initialPhoneNumber: '9855316514',
defaultCountry: 'RU'
})
const payload = await RNAccountKit.loginWithPhone()
console.log('payload.code', payload.code)
handleSignIn(payload.code)
}
const { container } = styles
return (
<View style={container}>
<Text>Put your phone number for Login</Text>
<Button title="Login" onPress={getToken} />
</View>
)
}