Skip to content

Instantly share code, notes, and snippets.

@oshyam
Created April 15, 2021 05:09
Show Gist options
  • Save oshyam/83c0c753d34b02bc3c9f0068f642d010 to your computer and use it in GitHub Desktop.
Save oshyam/83c0c753d34b02bc3c9f0068f642d010 to your computer and use it in GitHub Desktop.
//This is for educational purpose and a demo of login system
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
apiKey: "Your API Key Here",
authDomain: "login-demo-254f7.firebaseapp.com",
projectId: "login-demo-254f7",
storageBucket: "login-demo-254f7.appspot.com",
messagingSenderId: "228883805517",
appId: "1:228883805517:web:db9063121d6bf3a79ab304",
measurementId: "G-C8Q2HYKHY1"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const auth = firebase.auth();
//signup function
function signUp(){
var email = document.getElementById("email");
var password = document.getElementById("password");
const promise = auth.createUserWithEmailAndPassword(email.value,password.value);
//
promise.catch(e=>alert(e.message));
alert("SignUp Successfully");
}
//signIN function
function signIn(){
var email = document.getElementById("email");
var password = document.getElementById("password");
const promise = auth.signInWithEmailAndPassword(email.value,password.value);
promise.catch(e=>alert(e.message));
}
//signOut
function signOut(){
auth.signOut();
alert("SignOut Successfully from System");
}
//active user to homepage
firebase.auth().onAuthStateChanged((user)=>{
if(user){
var email = user.email;
alert("Active user "+email);
}else{
alert("No Active user Found")
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment