Firebase Authentication redirect when logged in with express.js

In my app I have an admin control panel that only allows admis to access. Here’s the code.

app.get('/acp', function (req, res) {
    var user = firebase.auth().currentUser;

    if (user) {
        // Logged in
        res.send('Hello world');
    } else {
        // Not logged in

But when the user is not logged in, he’ll be redirected to admin login page, which also works fine.

The problem is I don’t know how I can redirect the user to admin control panel when he’s logged in.

app.get('/admin', function (req, res) {
    res.sendFile(__dirname + '/public/admin.html');
});'/admin', function (req, res) {

    const email =;
    const password = req.body.password;

    firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {

        var errorCode = error.code;
        var errorMessage = error.message;


    res.redirect('/acp'); // the problem



signInWithEmailAndPassword returns a promise:'/admin', function (req, res, next) {

    const email =;
    const password = req.body.password;

        .signInWithEmailAndPassword(email, password)
        .then(function(user) { res.redirect('/acp'); })