diff --git a/examples/with-express-auth/index.js b/examples/with-express-auth/index.js index ff756347..0cfbf81e 100644 --- a/examples/with-express-auth/index.js +++ b/examples/with-express-auth/index.js @@ -87,7 +87,7 @@ const run = async () => { app.set('views', __dirname + '/views'); app.set('view engine', 'ejs'); - app.use(session({ secret: 'keyboard cat' })); + app.use(session({ secret: 'keyboard cat', saveUninitialized: true, resave: true })); app.use(bodyParser.urlencoded({ extended: false })); // Initialize Passport and restore authentication state, if any, from the session. @@ -95,12 +95,12 @@ const run = async () => { app.use(passport.session({})); app.get('/ui/login', (req, res) => { - res.render('login'); + res.render('login', { invalid: req.query.invalid === 'true' }); }); app.post( '/ui/login', - passport.authenticate('local', { failureRedirect: '/ui/login' }), + passport.authenticate('local', { failureRedirect: '/ui/login?invalid=true' }), (req, res) => { res.redirect('/ui'); } @@ -120,11 +120,7 @@ const run = async () => { }); }); - app.use( - '/ui', - ensureLoggedIn({ redirectTo: '/ui/login' }), - serverAdapter.getRouter() - ); + app.use('/ui', ensureLoggedIn({ redirectTo: '/ui/login' }), serverAdapter.getRouter()); app.listen(3000, () => { console.log('Running on 3000...'); diff --git a/examples/with-express-auth/views/login.ejs b/examples/with-express-auth/views/login.ejs index f18cad3d..6cc1d2c2 100644 --- a/examples/with-express-auth/views/login.ejs +++ b/examples/with-express-auth/views/login.ejs @@ -65,37 +65,7 @@ text-decoration: none; } - .container { - position: relative; - z-index: 1; - max-width: 300px; - margin: 0 auto; - } - .container:before, .container:after { - content: ""; - display: block; - clear: both; - } - .container .info { - margin: 50px auto; - text-align: center; - } - .container .info h1 { - margin: 0 0 15px; - padding: 0; - font-size: 36px; - font-weight: 300; - color: #1a1a1a; - } - .container .info span { - color: #4d4d4d; - font-size: 12px; - } - .container .info span a { - color: #000000; - text-decoration: none; - } - .container .info span .fa { + .message.error { color: #EF3B3A; } @@ -107,8 +77,10 @@ -

Username: bull, Password: board

+ <% if (invalid) { %> +

Invalid username or password.

+ <% } %>