Skip to content

Latest commit

 

History

History
91 lines (69 loc) · 1.98 KB

Readme.md

File metadata and controls

91 lines (69 loc) · 1.98 KB

Firebase Authentication Service

Steps to add in Node.Js Application

  1. Navigate in your Node.js (here, React) root directory
	npm init
	npm install --save firebase

Create a file, firebase.js and import firebase

	// Firebase App (the core Firebase SDK) is always required and
	// must be listed before other Firebase SDKs
	import * as firebase from "firebase/app";

	// Add the Firebase services that you want to use
	import "firebase/auth";
	import "firebase/firestore";

Initialize Firebase in your app

	// TODO: Replace the following with your app's Firebase project configuration
	var firebaseConfig = {
	  // ...
	};

	// Initialize Firebase
	firebase.initializeApp(firebaseConfig);

Get config file

  • Sign in to Firebase, then open your project.
  • Click the Settings icon, then select Project settings.
  • In the Your apps card, select the nickname of the app for which you need a config object.
  • Select Config from the Firebase SDK snippet pane.
  • Copy the config object snippet, then add it to your app's HTML.

Sample config file object looks like

var firebaseConfig = {
   apiKey: "",
   authDomain: "",
   databaseURL: "",
   projectId: "",
   storageBucket: "",
   messagingSenderId: ""
 };

Use the following methods in your application

  1. Sign Up
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // ...
});
  1. Login
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // ...
});
  1. Sign out
firebase.auth().signOut().then(function() {
  // Sign-out successful.
}).catch(function(error) {
  // An error happened.
});