Skip to content

Instantly share code, notes, and snippets.

@callmephilip
Created March 28, 2020 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save callmephilip/06c870c3479b90c9b03ee5f1a43a83d1 to your computer and use it in GitHub Desktop.
Save callmephilip/06c870c3479b90c9b03ee5f1a43a83d1 to your computer and use it in GitHub Desktop.
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