Unable to create Dynamic Short link with React-native-firebase - firebase

I'm catching an error with code: "links/failure"
const link = new firebase.links.DynamicLink(
"LINK",
"firebaseDomainLink"
).android
.setPackageName("packagename")
.ios.setBundleId("bundleID");
firebase
.links()
.createShortDynamicLink(link, 'UNGUESSABLE')
.then(url => {
console.log(url)
})
.catch(err => {
console.warn(err);
});
However when using "createDynamicLink" I am able to get the long dynamic link as the return.
Tested with Android Platform
Picture of Yellow error box

Related

Firebase remote config returning default value on android

I am using remote config in my react native project as following
useEffect(() => {
remoteConfig()
.setDefaults({
activation: 'project',
})
.then(() => remoteConfig().fetchAndActivate())
.catch(error => {
console.log(error)
})
.then(fetchedRemotely => {
if (fetchedRemotely) {
console.log('Configs were retrieved from the backend and activated.');
} else {
console.log('No configs were fetched from the backend, and the local configs were already activated',);
}
});
}, []);
var activation = remoteConfig().getValue('activation');
When I call activation.asString() in a function when a button is clicked, I first get the default value, not the one published. When I press cmd + s in the editor, the project is saved and the the get refreshed, then I start getting the remote value. And this happens only on android. I am implementing this correctly?

How do I fix firebase auth/netwok-request-failed when opened by social media browsers?

I recently had a bug to solve for a customer on my webapp. It is givng a
Firebase: Error(auth/network-request-failed)
However I also realize upon selecting 'Ok' on the alert, the browser redirects the user to login with their account, however has a my FIREBASE_AUTH_DOMAIN - {projectID}.firbaseapp.com .
This only occurs when user visit the login/signUp link via social media browser.
So I changed the signInWithPopUp -> signInWithRedirect.
And now I still get the error if I am redirected to the login/signUp page. How I do fix this?
const loginGoogle = async () => {
closeSnackbar();
const provider = new GoogleAuthProvider();
signInWithRedirect(auth, provider)
.then(() => {
createUserDoc(); //creates a userProfile document
enqueueSnackbar(
`Welcome ${
!auth.currentUser.displayName ? "" : auth.currentUser.displayName
}`,
{ variant: "success" }
);
})
.catch((error) => {
alert(error.message);
});
router.push(redirect || "/shop");
};

Firebase Phone Authentication error in React Native Code

I am trying to build a React Native app and firebase authentication. I am getting the Error:
RecaptchaVerifier is only supported in a browser HTTP/HTTPS environment with DOM support
auth
.signInWithPhoneNumber(number, appVerifier)) // <- this is where captcha is added
.then((result) => {
this.setState({ confirm: result });
this.setState({ buttonText: "Verify OTP" });
this.setState({ isLoading: false });
})
.catch((err) => {
console.log(`Error in phone auth: ${err}`);
});
The version which I am using of firebase is "react-native-firebase": "^5.6.0"
When I remove second parameter it gives an error which states two parameter required, found one
Are you sure you are using react-native-firebase phone auth with 5.X.X version. You can skip the appverifier from the method and instead use the following method from react-native-firebase. It will automatically open a window to verify the app and recaptha.
firebase.auth().signInWithPhoneNumber(phoneNumber)
.then(confirmResult => // save confirm result to use with the manual verification code)
.catch(error => /error);

How to correctly set up foreground notifications using react-native-firebase v5?

We have a react-native app that runs its notifications through FCM with the following environment:
react-native: 0.59.10,
react-native-firebase: 5.5.6
All the configs have been set up, certificates provisioned, etc. Until the very present time, notifications have been working like a clock, but recently we stopped receiving notifications in the foreground.
Here's the NotificationsManager code:
import firebase from 'react-native-firebase';
const CHANNEL = 'default';
...
const localNotificationListener = React.useRef();
const notificationOpenListener = React.useRef();
const onTokenRefreshListener = React.useRef();
const receiveForegroundPN = (n) => {
const notification = new firebase.notifications.Notification()
.setNotificationId(n.notificationId)
.setTitle(n.title)
.setSubtitle(n.subtitle)
.setBody(n.body)
.setData(n.data);
if (Platform.OS === 'android') {
notification
.android.setChannelId(CHANNEL)
.android.setSmallIcon('ic_launcher');
}
firebase.notifications().displayNotification(notification);
};
React.useEffect(() => {
const channel = new firebase.notifications.Android.Channel(
CHANNEL,
'Bank Notifications',
firebase.notifications.Android.Importance.Max,
).setDescription('*****');
firebase.notifications().android.createChannel(channel);
localNotificationListener.current = firebase.notifications().onNotification(receiveForegroundPN);
notificationOpenListener.current = firebase.notifications().onNotificationOpened(openNotification);
onTokenRefreshListener.current = firebase.messaging().onTokenRefresh((fcmToken) => {
registerToken({
device_token: fcmToken,
});
});
runFlow();
return () => {
localNotificationListener.current();
notificationOpenListener.current();
onTokenRefreshListener.current();
};
}, []);
Notifications work just fine on both platforms while the app is in the background, but never show when the app is in the foreground.
I've tried setting show_on_foreground: "true", but that didn't help. Actually, I tried logging anything in the receiveForegroundPN method but it was never called, i.e. it looks like notifications are never received from firebase when app is running.
What might be the issue here and possible solutions to make notifications work?
Update
All of a sudden, within the hour of posting this, iOS started to receive foreground notifications. Android still doesn't work, yet it used to.
I am having a similar issue as well.. ,
The onNotification method doesn't get trigerred so i tried the onMessage method instead which seems to work for foreground.
firebase.messages().onMessage(msg => {
// ... your code here
});
Iterating on Amr's answer.
As per documentation, you must hook into firebase's callbacks to get notified when a push notification is received in foreground.
From that point you can decide how to handle the message.
The simplest way is to display an alert Alert.alert('A new FCM message arrived!', JSON.stringify(remoteMessage)); or
You can use another library to display a local notification. Here is an example using react-native-notifications library:
// Just call the hook in some root component that's always present
export const useDisplayRemoteNotifications: () => void = () => {
useEffect(() => {
return messaging().onMessage(async remoteMessage => {
Notifications.postLocalNotification({
title: remoteMessage.notification?.title || '',
body: remoteMessage.notification?.body || '',
fireDate: dayjs().add(1, 'second').toDate(), // one second later
});
});
}, []);
};

admin.ref.on() is not working while once() works perfectly

I found this strange problem where documented feature seems not to be working.
I have this working code:
exports.getEvents = functions.https.onRequest((req, res) => {
cors(req, res, () => {
admin.database().ref('events').orderByValue().once('value', function(snapshot) {
res.status(200).send(snapshot.val());
}).catch(error => {
console.error('Error while reading data', error);
res.status(403).send('Error: ' + error);
});
When I change from once() to on() I get errors.
What I want to achieve is to have server send new JSON payload when there are changes to eventssince I have app that reads events.json directly and I can use only link to provide data (so all SDK functions are out). Am I doing something wrong?
Error log:
TypeError: admin.database(...).ref(...).orderByValue(...).on(...).catch is not a function
at cors (/user_code/index.js:24:11)
at cors (/user_code/node_modules/cors/lib/index.js:188:7)
at /user_code/node_modules/cors/lib/index.js:224:17
at originCallback (/user_code/node_modules/cors/lib/index.js:214:15)
at /user_code/node_modules/cors/lib/index.js:219:13
at optionsCallback (/user_code/node_modules/cors/lib/index.js:199:9)
at corsMiddleware (/user_code/node_modules/cors/lib/index.js:204:7)
at exports.getEvents.functions.https.onRequest (/user_code/index.js:19:2)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:26:47)
at /var/tmp/worker/worker.js:635:7
You've tried to add a .catch to the end of your statement. .on doesn't support this function.
See some sample code below which should fix your issue.
admin.database().ref('/somePath')
.orderByValue()
.on('child_added', (snapshot, prevChildKey) => {
console.log(snapshot.val()); // JSON
}, err => {
// Error is thrown here - Not in a .catch
});

Resources