Skip to content

Instantly share code, notes, and snippets.

@rob-balfre
Created May 27, 2018 22:02
Show Gist options
  • Save rob-balfre/25270a48971c25bf10efb03676a92fdc to your computer and use it in GitHub Desktop.
Save rob-balfre/25270a48971c25bf10efb03676a92fdc to your computer and use it in GitHub Desktop.
Example of Sapper using Passport
import express from 'express';
import passport from 'passport';
import {Strategy} from 'passport-github';
import compression from 'compression';
import sapper from 'sapper';
import serve from 'serve-static';
import {routes} from './manifest/server.js';
import App from './App.html';
import _ from '../SECRETS';
passport.use(new Strategy({
clientID: _.GITHUB_CLIENT_ID,
clientSecret: _.GITHUB_CLIENT_SECRET,
callbackURL: _.GITHUB_CALLBACK_URL,
}, (accessToken, refreshToken, profile, cb) => {
console.log('success');
return cb(null, profile);
}));
passport.serializeUser(function (user, cb) {
cb(null, user);
});
passport.deserializeUser(function (obj, cb) {
cb(null, obj);
});
express()
.use(passport.initialize())
.get('/auth/login', passport.authenticate('github'))
.get('/auth/callback',
passport.authenticate('github', {failureRedirect: '/login'}),
(req, res) => {
res.redirect('/');
})
.use(
compression({threshold: 0}),
serve('assets'),
sapper({
routes,
App
})
)
.listen(process.env.PORT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment