Reputation: 4859
I created a function in react-native that looks like this one
static async myFunction(){
await RNSFAuthenticationSession.getSafariData(url,scheme).then(async (callbackUrl) => {
const isValid = await MyClass.checkIfValid(data);
if (isValid) {
return true;
} else {
return false;
}
}
and I am calling it in this way
const isValid = await MyClass.myFunction();
alert(isValid); // undefined
isValid
contains an undefined
value. Do you know how can I fix this?
Upvotes: 2
Views: 99
Reputation: 989
You forgot to return Promise
static async myFunction(){
return await RNSFAuthenticationSession.getSafariData(url,scheme).then(async (callbackUrl) => {
const isValid = await MyClass.checkIfValid(data);
if (isValid){
return true;
} else {
return false;
}
}
and you can simplify your code
static myFunction() {
return RNSFAuthenticationSession.getSafariData(url, scheme)
.then(() => MyClass.checkIfValid(data))
}
Upvotes: 1