How to use firebase features in react native - firebase

I want to write a mobile app using react native. And I want to use firebase because it saves me a lot of time. I used firebase before for my web app and it worked pretty well. Now that react native is actually a real native app, I am thinking if I can use firebase features for my app. For example, third-party authentication, deep link, etc. I know that even though all written in Javascript, react native is not web app at all. There are specifically several features I want to use. Google Auth, Cloud Messaging, and some Analytics features. Is there any way I can put them in my app as if I am writing my app in Swift or Java?

First of all you might need to add firebase under dependencies in package.json file
"dependencies": {
"firebase": "^3.9.0",
"react": "^16.0.0-alpha.6",
"react-native": "0.44.0",
},
After that Import firebase
import * as firebase from 'firebase';
Then do the usual firebase initialization
const config = {
apiKey: "xxxxxxxxxx-xxxxxxxxxxxxx",
authDomain: "xxxxxxxxxxx.firebaseapp.com",
databaseURL: "https://xxxxxxxxxx.firebaseio.com",
projectId: "xxxxxxxxxx",
storageBucket: "xxxxxxxxxx.appspot.com",
messagingSenderId: "xxxxxxxxxx"
};
const firebaseApp = firebase.initializeApp(config);
Now that have connected firebase to your react-native app, you can retrieve the contents from the database like this
firebaseApp.database().ref("xxxxxx").on('value', (snap) => {
console.log(snap.val());
});
The remaining can be easily figured out similarly
If you still need more help you can check out the following link : https://firebase.googleblog.com/2016/01/the-beginners-guide-to-react-native-and_84.html

Related

Flutter user add their own firebase database

I am new in Flutter and i'm try to build aplication working with the database. In app I would for the user to add their own firebase database to working with with app. This is possible to add firebase database after build the app? Please information about this.
Thanks for any sugestions
You can specify the configuration data for the Firebase project in your Dart code as shown in this example in the FlutterFire docs:
FirebaseOptions get firebaseOptions => const FirebaseOptions(
appId: '1:448618578101:ios:0b650370bb29e29cac3efc',
apiKey: 'AIzaSyAgUhHU8wSJgO5MVNy95tMT07NEjzMOfz0',
projectId: 'react-native-firebase-testing',
messagingSenderId: '448618578101',
);
Future<void> initializeDefault() async {
FirebaseApp app = await Firebase.initializeApp(
options: DefaultFirebaseConfig.platformOptions,
);
print('Initialized default app $app');
This means you can get the necessary data from the user or in another way at runtime, and only then initialize the app.
If you don't want to request the user to enter these details manually, you can use the REST API for managing projects to get a list of the user's projects. There is no Flutter/Dart wrapper for this API that I know off, so you'll have to write that yourself.

Use Firebase Realtime Database in Flutter Web App

I'm a beginner in Flutter and I want to connect my Flutter Web App to Firbase Realtime Database. My goal is to add some sample data inside the database when I click a button.
At this moment I have added inside the web/index.html file the following
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-firestore.js"></script>
<script>
var firebaseConfig = {
apiKey: "...",
authDomain: "...",
databaseURL: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "...",
appId: "...",
measurementId: "...",
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
In my pubspec.yaml file I have added the following dependencies:
firebase: ^7.3.2
firebase_core: ^0.5.2
firebase_database: ^4.3.0
My main.dart file contains a simple main() function like below
void main() {
runApp(MyApp());
}
And the MyApp() stateless widget.
Do I have to use the .initializeApp() and pass inside it the project's constraints (apiKey, authDomain etc.)?
Can someone give me some hints because i have no idea what to do, i'm pretty much confused at this moment.
Thank you for your time
If you look at the platform support table on firebase.flutter.dev, you'll see that the FlutterFire libraries don't support accessing Realtime Database in web apps yet. Work to add support is under way, but there's no estimate on when it will be released.
For the moment, if you want to use the Firebase Realtime Database in a Flutter web app, you'll have to use the firebase-dart library.

How can I initialize the Firebase Admin SDK in spring-boot application using kotlin

I would like to get data from Firebase. I found some tutorials, but all is using Google Credential ServiceAccount to initialize firebase app. this's is tutorial that i found :
https://medium.com/techwasti/spring-boot-firebase-crud-b0afab27b26e , and else tutorial i found, almost like that too, is using ServiceAccount.
But the problem is i cannot get the ServiceAccount from this firebase because it's from third party. that's mean the owner of firebase don't want to give ServiceAccount.json to me, but they give me firebase config to me, like this :
const firebaseConfig = {
apiKey: "apkey",
authDomain: authdomain",
databaseURL: "databaseurl",
projectId: "projectid",
storageBucket: "storragebucket",
messagingSenderId: "messagesenderid",
appId: "appid",
measurementId: "measurementid"
};
So, how can i initialize this firebase using kotlin in my java springboot aplication?
i had try to find the solution, but not found anything,
I would be glad for any help.
If you want to initialize the Firebase Admin SDK, you will need a service account. There are no alternatives for this.
The config for the front end web app that you're showing here will not work at all. That config is only used for frontend apps that are acting as clients on behalf of the end user.

Why does the email-password example work?

Taking my first steps with Firebase. Just a few pointers to documents explaining what is going on will help.
I have set up a new firebase web project and connected my dev environment with the firebase sdk. Now when I drop the email-password quickstart into the project it works. (after enabling email/password sign in.)
But wait: This quickstart html file does not contain any configuration that the firebase console tells me to paste:
var config = {
apiKey: "xxx",
authDomain: "xxx.xxx.com",
databaseURL: "https://xxx.xxx.com",
projectId: "xxxx",
storageBucket: "xxx.xxx.com",
messagingSenderId: "xxx"
};
Does the local firebase server add the configuration in the background? When and where do I have to add this configuration to web pages?
If you check line 35 of that quickstart, you'll find this magic include:
<script src="/__/firebase/init.js"></script>
This is an auto-generated file by Firebase Hosting, that contains precisely the code that initializes the connection to the Firebase backend services of your project.
If you'd like to learn more about it, read:
Easier configuration for Firebase on the web
SDK imports and automatic initialization
SDK auto-configuration

Using Same Firebase App With Web and Mobile App

So say I am building a web app using React and also a mobile app that allows users to take a photo using React Native. I want to allow users to use the same login credentials when signing into the web app and also the mobile app. Can I use the same Firebase info for both the web app and mobile app? Like just include the snippet below in both code bases to allow them to both use the same database, storage, etc?
<script src="https://www.gstatic.com/firebasejs/3.6.1/firebase.js"></script>
<script>
// Initialize Firebase
// TODO: Replace with your project's customized code snippet
var config = {
apiKey: "<API_KEY>",
authDomain: "<PROJECT_ID>.firebaseapp.com",
databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
storageBucket: "<BUCKET>.appspot.com",
messagingSenderId: "<SENDER_ID>",
};
firebase.initializeApp(config);
</script>
A single Firebase project can be used as the back-end for many (iOS, Web and Android) apps. All these apps will be talking to the same back-end services.
So if you create two web applications on a single Firebase project, those apps will be using the same database, the same list of users, the same stored files, etc. If you then add an iOS or Android app, that will also be accessing the same users/database/files.

Resources