Created
March 28, 2020 10:58
-
-
Save callmephilip/06c870c3479b90c9b03ee5f1a43a83d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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