node.js and Firebase session control
<p>I am building an app on node.js using firebase as storage.</p>

<p>When logging with this function</p>

<p><code>firebase.auth().signInWithEmailAndPassword(N1,N2).catch(function(error)</code></p>

<p>The user successfully logs in but when i open my localhost from another browser the previous user logged in state shows.</p>

<p>I think the session is being overwritten or something like that</p>

<p>please help me here is my server.js file:-</p>

<pre><code>const express = require('express');
var assert = require('assert');
var bodyParser = require("body-parser");
var path = require('path');
var app = express();
const session = require('express-session');
var OpenTok = require('opentok'),
    opentok = new OpenTok('xxxxxxxxx', 'xxxxxxxxxxxxxxxx');
const FirebaseStore = require('connect-session-firebase')(session);
const firebase = require('firebase');
const ref = firebase.initializeApp({
  apiKey: "xxxxxxxxxxxxx",
    authDomain: "xxxxxxxxxxxx",
    databaseURL: "https://xxxxxxxxx",
    storageBucket: "xxxxxxxxxxxx",
    messagingSenderId: "xxxxxxxxxxx"
});

app.set('port', (process.env.PORT || 5000));
app.set('views', __dirname + '/views');
app.use(bodyParser.urlencoded({ extended: true }));
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'views')));
app.set('views', __dirname + '/views');
app.use(express.static(__dirname + '/public'));
app.use(session({resave: false, saveUninitialized: true, secret:'xxxxxx'}));
app.use(bodyParser.json());

express()
  .use(session({
    store: new FirebaseStore({
      database: ref.database()
    }),
    secret: 'xxxxxxxxx',
    resave: true,
    saveUninitialized: true
  }));
app.get('/', function(req, res){
    firebase.auth().onAuthStateChanged(function(user){
        if(user){
            res.redirect("/admin");
            console.log(user.email);
        } 
        else {
            res.render('index2.ejs');   
        }
        }); 
});
</code></pre>

<p>I used this package <strong>Connect Session Firebase</strong> to debug, do something but it didn't help if I m doing anything wrong please tell.</p>

<p>the login code</p>

<pre><code>app.post('/signin',function (req, res){
    var N1 = req.body.N1_in;
    var N2 = req.body.N2_in;

        firebase.auth().signInWithEmailAndPassword(N1,N2).catch(function(error) {
        }); 
        function function1() {
            // stuff you want to happen right away

        }

        function function2() {
            // all the stuff you want to happen after that pause
            res.redirect('/admin');
        }

        // call the first chunk of code right away
        function1();

        // call the rest of the code and have it execute after 3 seconds
        setTimeout(function2, 2500);
}); 
</code></pre>