-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53c92a8
commit cb52c77
Showing
10 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/*eslint-disable*/ | ||
const passport = require('passport'); | ||
const FacebookStrategy = require('passport-facebook').Strategy; | ||
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy; | ||
const { User } = require('../models'); | ||
passport.use( | ||
new FacebookStrategy( | ||
{ | ||
clientID: process.env.FACEBOOK_CLIENT_ID, | ||
clientSecret: process.env.FACEBOOK_CLIENT_SECRET, | ||
callbackURL: 'http://localhost:8000/v1/social/facebook/callback', | ||
profileFields: ['id', 'name', 'emails', 'picture.type(large)'], | ||
}, | ||
(accessToken, refreshToken, profile, done) => { | ||
console.log({ profile }); | ||
// return done(null); | ||
User.findOne({ where: { facebookId: profile.id } }) | ||
.then((user) => { | ||
if (user) { | ||
return done(null, user); | ||
} | ||
const name = `${profile.name.givenName} ${profile.name.familyName}`; | ||
const newUser = new Users({ | ||
facebookId: profile.id, | ||
name: name, | ||
provider: profile.provider, | ||
email: profile.emails ? profile.emails[0].value : null, | ||
firstName: profile.name.givenName, | ||
lastName: profile.name.familyName, | ||
profilePicture: profile.photos[0].value, | ||
password: null, | ||
}); | ||
newUser.save((err, user) => { | ||
if (err) { | ||
return done(err, false); | ||
} | ||
|
||
return done(null, user); | ||
}); | ||
}) | ||
.catch((err) => { | ||
return done(err, false); | ||
}); | ||
} | ||
) | ||
); | ||
|
||
passport.use( | ||
new GoogleStrategy( | ||
{ | ||
clientID: process.env.GOOGLE_CLIENT_ID, | ||
clientSecret: process.env.GOOGLE_CLIENT_SECRET, | ||
callbackURL: 'http://localhost:8000/v1/google/callback', | ||
}, | ||
function (accessToken, refreshToken, profile, done) { | ||
// return done(null); | ||
Users.findOne({ where: { googleId: profile.id } }) | ||
.then((user) => { | ||
if (user) { | ||
return done(null, user); | ||
} else { | ||
const name = `${profile.name.givenName} ${profile.name.familyName}`; | ||
const newUser = new Users({ | ||
name: name, | ||
googleId: profile.id, | ||
provider: profile.provider, | ||
email: profile.emails ? profile.emails[0].value : null, | ||
firstName: profile.name.givenName, | ||
lastName: profile.name.familyName, | ||
profilePicture: profile.photos[0].value, | ||
password: null, | ||
}); | ||
newUser.save((err, user) => { | ||
if (err) { | ||
return done(err, false); | ||
} | ||
return done(null, user); | ||
}); | ||
} | ||
}) | ||
.catch((err) => { | ||
return done(err, false); | ||
}); | ||
} | ||
) | ||
); |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const passport = require('passport'); | ||
|
||
router.use(passport.initialize()); | ||
router.get( | ||
'/facebook', | ||
passport.authenticate('facebook', { | ||
session: false, | ||
scope: ['public_profile', 'email'], | ||
}) | ||
); | ||
|
||
router.get( | ||
'/facebook/callback', | ||
passport.authenticate('facebook', { | ||
successRedirect: '/', | ||
failureRedirect: '/', | ||
session: false, | ||
}) | ||
); | ||
|
||
router.get( | ||
'/google', | ||
passport.authenticate('google', { | ||
session: false, | ||
scope: ['profile', 'email'], | ||
accessType: 'offline', | ||
approvalPrompt: 'force', | ||
}) | ||
); | ||
router.get( | ||
'/google/callback', | ||
passport.authenticate('google', { | ||
failureRedirect: '/', | ||
session: false, | ||
}) | ||
); | ||
|
||
module.exports = router; |
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