Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
app.get('/', (req, res) => {
// When logged in user object is attached to the request
if (!req.user) {
res.redirect('/login');
return;
}
res.send(`Hello ${req.user.emails[0].address}`);
});
app.get('/login', (req, res) => {
res.send(`<form action="/login" method="post">
<div>
<label>Username:</label>
<input type="text" name="username"/>
</div>
<div>
<label>Password:</label>
<input type="password" name="password"/>
</div>
<div>
<input type="submit" value="Log In"/>
</div>
</form>`);
});
app.post('/login', passport.authenticate('local', {
successRedirect: '/',
failureRedirect: '/error',
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment