Skip to content

Instantly share code, notes, and snippets.

@JesusMurF
Created March 31, 2018 09:33
Show Gist options
  • Save JesusMurF/41499117ea67a2cdd55a80bbb7f6279b to your computer and use it in GitHub Desktop.
Save JesusMurF/41499117ea67a2cdd55a80bbb7f6279b to your computer and use it in GitHub Desktop.
Server file for Instagram SignUp
const express = require('express');
const session = require('express-session');
const passport = require('passport');
const exphbs = require('express-handlebars');
const bodyParser = require('body-parser');
require('./config/db');
const app = express();
app.engine('handlebars', exphbs({ defaultLayout: 'main' }));
app.set('view engine', 'handlebars');
const ensureAuthenticated = require('./controllers/authentication_instagram');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(
session({
saveUninitialized: true,
resave: true,
secret: 'secret'
})
);
app.use(passport.initialize());
app.use(passport.session());
app.get('/', (request, response) => {
response.render('home');
});
app.get('/profile', ensureAuthenticated, (request, response) => {
const { instagram } = request.user;
response.render('profile', { user: instagram });
});
app.get('/logout', function(req, res) {
req.logout();
res.redirect('/');
});
app.get('/auth/instagram', passport.authenticate('instagram'));
app.get(
'/auth/instagram/callback',
passport.authenticate('instagram', {
successRedirect: '/profile',
failureRedirect: '/login'
})
);
const port = 9000;
app.listen(port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment