0

Let's say person A creates an account and logs In. So now when person B opens the website, he is already logged in in the person A's account.

exports.sendSignUpRequest = function (request, res) {

const email = request.body.username;
const password = request.body.password;


firebase.auth().createUserWithEmailAndPassword(email, password).then(function(user) {
    var user = firebase.auth().currentUser;
    console.log(user.uid);
    const dataBaseRef = firebase.database().ref('users/'+user.uid+'/credentials');
    dataBaseRef.set({
        email : email,
    });
    res.redirect('/');
}, function(error) {
    console.log("error has happened because of : "+ error.message);
    res.render('signup', {error: error.message});
});

};

exports.sendLoginRequest = function (request, res) {

const email = request.body.username;
const password = request.body.password;
firebase.auth().signInWithEmailAndPassword(email, password)
    .then(function(firebaseUser) {
        console.log(firebaseUser.user.email);            
        res.redirect('/');            
    }).catch(function(error) {
    res.render('login', {error: error.message, success:''});
});

};

exports.home = function (req, res) {

let user = firebase.auth().currentUser;

if (user) {
            console.log('user is signed in : '+ user.email);
            res.render('home', {user : user});
        } else {
            console.log('user is not signed in');
            res.render('home', {user : null});
        }

};

//RULES FOR THE FIREBASE DATABASE { /* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */ "rules": { ".read" : true, ".write" : true, "products": { ".indexOn": ["featuredProduct","type", "productId"], ".write" : "auth.token.admin == true" }, "customerDiary" : { ".write" : "auth.token.admin == true" }, "users":{ "$user_id": { ".read": "$user_id === auth.uid", ".write": "$user_id === auth.uid", "orders":{ ".indexOn": ["orderStatus"] }
}
} } }

  • 3
    Welcome to StackOverflow! What is your question? – Hille Feb 05 '19 at 07:49
  • The question is that whats happening right now is, whenever one user login into his account, that account gets logged in in everyone's session. this should not happen. The person should login to get logged in, right now if any of user has logged in, the rest of the users automatically gets logged in into the wrong account – avdeep sandhu Feb 05 '19 at 17:39
  • You seem to be signing in the user on a server environment applying this session to all connected users. Instead you should call the sign-in APIs from the browser. – bojeil Mar 05 '19 at 07:45

0 Answers0