react native firebase
// Using npm
npm install --save @react-native-firebase/app
# create your firebase android project and follow the steps for implementations.
# check: https://rnfirebase.io/#generating-android-credentials
react native firebase
// Using npm
npm install --save @react-native-firebase/app
# create your firebase android project and follow the steps for implementations.
# check: https://rnfirebase.io/#generating-android-credentials
firebase connecten
package com.example.phonechat;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
public class RegistrationActivity extends AppCompatActivity {
private Button mRegistration;
private EditText mEmail, mPassowrd, mName;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener firebaseAuthStateListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
firebaseAuthStateListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user!=null) {
Intent intent = new Intent(getApplication(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
return;
}
}
};
mAuth = FirebaseAuth.getInstance();
mRegistration = findViewById(R.id.registration);
mEmail = findViewById(R.id.gmail);
mName = findViewById(R.id.name);
mPassowrd = findViewById(R.id.password);
mRegistration.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String name = mName.getText().toString();
final String email = mEmail.getText().toString();
final String password = mPassowrd.getText().toString();
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(activity: getApplication(), new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(getApplicationContext(), "Sign in ERROR", Toast.LENGTH_SHORT).show();
}else{
String userId = mAuth.getCurrentUser().getUid();
DatabaseRefere currentUSerDb = FirebaseDatabase.getInstace().getRefernce().child("users").child(userId);
Map userinfo = new HashMap<>();
userInfo.put( k: "email", email);
userInfo.put( k: "name", name);
userInfo.put( k: "profileImageErl", v: "default");
currentUSerDb.updateChilderen(userInfo);
}
}
});
}
});
}
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(firebaseAuthStateListener);
}
@Override
protected void onStop() {
super.onStop();
mAuth.removeAuthStateListener(firebaseAuthStateListener);
}
}
firebase for React Native
import { firebase } from "@firebase/app";
//import modules
import "@firebase/auth";
const firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
};
//Delete that after realisation of authContext !!
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
//Auth with email and password
//Put into export App
const [isAuthenticated, setIsAuthenticated] = useState(false);
useEffect(() => {
firebase
.auth()
.signInWithEmailAndPassword("[email protected]", "password")
.then((user) => {
console.log(user);
setIsAuthenticated(true);
})
.catch((e) => {
console.log(e);
});
}, []);
react native firebase
/* Answer to: "react native firebase" */
/*
React Native Firebase is the officially recommended collection
of packages that brings React Native support for all Firebase
services on both Android and iOS apps.
*/
react native firebase
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services' // <- Add this line
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us