Skip to content

Instantly share code, notes, and snippets.

@piyushgarg-dev
Last active April 24, 2020 18:13
Show Gist options
  • Select an option

  • Save piyushgarg-dev/67f17969f2f02e4e321b7b3ffc3f5b3a to your computer and use it in GitHub Desktop.

Select an option

Save piyushgarg-dev/67f17969f2f02e4e321b7b3ffc3f5b3a to your computer and use it in GitHub Desktop.
const express = require('express');
const passport = require('passport');
const session = require('express-session');
const app = express();
app.use(session({ secret: 'mysecret', resave: true, saveUninitialized: true }));
app.use(passport.initialize())
app.use(passport.session())
app.use(express.json())
app.get('/', (req, res) => {
if(req.user) {
res.send(`Hey There.... You are ${req.user.email}`)
}
else{
res.send('Hey.. I dont know who are you??? ')
}
})
app.post('/login', passport.authenticate('local'), (req, res) => {
res.send('Loggin Sucess')
})
app.listen(9000, () => console.log(`Server running at 9000`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment