-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#167574878 Facebook Social Login #17
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
getUserAgent, | ||
createSocialUsers, | ||
serverResponse, | ||
getSocialUserData | ||
} from '../helpers'; | ||
/** | ||
* @export | ||
* @class Auth | ||
*/ | ||
class Auth { | ||
/** | ||
* @name facebookSocialLogin | ||
* @async | ||
* @static | ||
* @memberof Auth | ||
* @param {Object} request express request object | ||
* @param {Object} response express response object | ||
* @returns {JSON} JSON object with details of new user | ||
*/ | ||
static async facebookSocialLogin(request, response) { | ||
const { devicePlatform, userAgent } = getUserAgent(request); | ||
const { ip } = request; | ||
const { givenName, familyName, email } = getSocialUserData( | ||
request, | ||
'facebook' | ||
); | ||
const data = { | ||
firstName: givenName, | ||
lastName: familyName, | ||
email, | ||
devicePlatform, | ||
userAgent, | ||
ipAddress: ip | ||
}; | ||
const user = await createSocialUsers(data); | ||
delete user.password; | ||
serverResponse(response, 200, user); | ||
} | ||
} | ||
export default Auth; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import models from '../database/models'; | ||
import generateToken from './generateToken'; | ||
import dateHelper from './dateHelper'; | ||
|
||
const { User, Session } = models; | ||
const { expiryDate } = dateHelper; | ||
/** | ||
* @name createSocialUser | ||
* @description function that creates a new user in via socialLogin | ||
* @param { Object } data to check in the database | ||
* @returns { Object } value indicating if username exists | ||
*/ | ||
const createSocialUser = async (data) => { | ||
const { | ||
firstName, | ||
lastName, | ||
email, | ||
ipAddress, | ||
userAgent, | ||
devicePlatform | ||
} = data; | ||
const expiresAt = expiryDate(devicePlatform); | ||
const users = await User.findOrCreate({ | ||
where: { email }, | ||
defaults: { | ||
firstName, | ||
lastName, | ||
} | ||
}); | ||
const result = { ...users[0].dataValues }; | ||
const { id } = result; | ||
const token = generateToken({ id }); | ||
await Session.create({ | ||
userId: id, | ||
token, | ||
expiresAt, | ||
userAgent, | ||
ipAddress, | ||
devicePlatform | ||
}); | ||
result.token = token; | ||
return result; | ||
}; | ||
export default createSocialUser; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import passport from 'passport'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parsing error: 'import' and 'export' may appear only with 'sourceType: module' |
||
import { Strategy as FacebookStrategy } from 'passport-facebook'; | ||
import passportCallback from '../middlewares/passportCallback'; | ||
|
||
export default () => { | ||
passport.use( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected newline after '(' function-paren-newline |
||
new FacebookStrategy( | ||
{ | ||
clientID: process.env.FACEBOOK_APP_ID, | ||
clientSecret: process.env.FACEBOOK_APP_SECRET, | ||
callbackURL: process.env.REDIRECT_URL, | ||
profileFields: ['id', 'first_name', 'last_name', 'photos', 'email'] | ||
}, | ||
passportCallback | ||
) | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected newline before ')' function-paren-newline |
||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'serverResponse' is defined but never used. Allowed unused vars must match /should|expect/ no-unused-vars