So I'm ultimately trying to make in node a login page. If a person attempts to go to a different location to begin with they should be routed to the login page. 

I'm using "/" as the redirect to the "/login/". "/login/" contains the form to enter the username/password. Once they enter in the information it then routes back to "/". 

Hitting a few problems. If I exclude the code I have for the redirect if the original url was "/" and a person goes to "/login/" then they can fill out the form and it redirects.

If I keep the code that redirects it automatically redirects to the login page and then reloads to the login page because of the redirect. It's some weird loop that I can't get out of. I know I could just put another end to the "/login/" but I'd like to keep it "/". 

Any ideas on fixing the redirect loop? EDIT: So I know what the problem is. I'm not storing for comparison (not using session). Any clue on the best middleware to use for checking with session?

How about adding authentication or even adding the usernames/password to a data structure?

Below is the code I've come up with:

```
 const express = require("express"); //Express
 const path = require ("path");
 const session = require("express-session"); //Express Session
 const app = express();
 const mustache = require ("mustache");
 const mustacheExpress = require('mustache-express');
 const bodyParser = require ("body-parser");

 app.use(bodyParser.json());
 app.use(bodyParser.urlencoded({extended:true}));

app.engine('mustache', mustacheExpress());
app.set('views', './views')
app.set('view engine', 'mustache')

app.use(session({
  secret: 'keyboard cat',
  resave: false,
  saveUninitialized: false,
  cookie:{}
 }));

app.use((req, res, next) => {
    if (req.originalUrl === '/') {
    res.redirect("/login/");
  }
  next();
});

const list = [
  {
    username: "",
    password: "",
   }
];

const data = {
  users:list
 };

 app.get('/login/', function (req, res) {
   res.render("users", data);
});

app.post("/", function(req, res){
  console.log(req.body);
  let username = req.body.username;
  let password = req.body.password;
  let response = `Here are your credentials for the site: <br/>
  This is your username: ${username} <br/>
  This is your password: ${password} <br/>
  <img src="http://media1.giphy.com/media/c54YHGDH63jJC/giphy.gif"/>`
  res.send(response);
});

app.post("/", function (req, res) {
  console.log(list);
  list.push({username:req.body.username});
  list.push({username:req.body.password});
  res.redirect('/');
})

app.listen(3000, function () {
  console.log('Creating login page');
})

```