Skip to content

Commit

Permalink
Show error message
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Jan 19, 2022
1 parent 77ebc4a commit e779507
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 40 deletions.
12 changes: 4 additions & 8 deletions examples/with-express-auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,20 @@ 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.
app.use(passport.initialize({}));
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');
}
Expand All @@ -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...');
Expand Down
36 changes: 4 additions & 32 deletions examples/with-express-auth/views/login.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -107,8 +77,10 @@
<input type="text" name="username" placeholder="Username"/>
<input type="password" name="password" placeholder="Password"/>
<button>Login</button>

<p class="message">Username: bull, Password: board</p>
<% if (invalid) { %>
<p class="message error">Invalid username or password.</p>
<% } %>
</form>
</div>
</div>

0 comments on commit e779507

Please sign in to comment.