Last active
June 24, 2018 07:37
-
-
Save AndrejGajdos/74cd18b6533963c5e83beb1a19c62ad8 to your computer and use it in GitHub Desktop.
koa router with routes for authentication project. Whole file is available https://github.com/AndrejGajdos/auth-flow-spa-node-react/blob/master/script/server.js
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
const auth = require('./controllers/auth'); | |
const router = new Router(); | |
router | |
/* Handle Login POST */ | |
.post('/login', ctx => passport.authenticate('local', (err, user) => { | |
if (!user) { | |
ctx.throw(401, err); | |
} else { | |
ctx.body = user; | |
return ctx.login(user); | |
} | |
})(ctx)) | |
/* GET User Profile */ | |
.get('/users/profile', auth.getLoggedUser) | |
/* Handle Logout POST */ | |
.get('/logout', (ctx) => { | |
ctx.logout(); | |
ctx.body = {}; | |
}) | |
/* Handle Login Facebook */ | |
.get('/auth/facebook', passport.authenticate('facebook')) | |
.get( | |
'/auth/facebook/callback', | |
passport.authenticate('facebook', { | |
successRedirect: '/facebook/success/', | |
failureRedirect: '/', | |
}), | |
); | |
app.use(router.routes()).use(router.allowedMethods()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment