Created
May 27, 2018 22:02
-
-
Save rob-balfre/25270a48971c25bf10efb03676a92fdc to your computer and use it in GitHub Desktop.
Example of Sapper using Passport
This file contains 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
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