Toggle navigation
Toggle navigation
This project
Loading...
Sign in
강연욱
/
myYoutube
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
2
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Flare-k
2020-06-17 21:27:18 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6aa7694298c95befe611892a3bb051821eff7eaa
6aa76942
1 parent
dc8b2cb4
[Authenticate] Facebook Login using passport
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
9 deletions
controllers/userController.js
package.json
passport.js
controllers/userController.js
View file @
6aa7694
...
...
@@ -80,13 +80,30 @@ export const postGithubLogin = (req, res) => {
export
const
facebookLogin
=
passport
.
authenticate
(
"facebook"
);
export
const
facebookLoginCallback
=
(
accessToken
,
refreshToken
,
profile
,
cb
)
=>
{
console
.
log
(
accessToken
,
refreshToken
,
profile
,
cb
);
// http://www.passportjs.org/packages/passport-facebook/ 참고하였습니다.
export
const
facebookLoginCallback
=
async
(
_
,
__
,
profile
,
cb
)
=>
{
const
{
_json
:
{
id
,
name
,
email
},
}
=
profile
;
try
{
const
user
=
await
User
.
findOne
({
email
});
if
(
user
)
{
user
.
facebookId
=
id
;
user
.
avatarUrl
=
`https://graph.facebook.com/
${
id
}
/picture?type=large`
;
user
.
save
();
return
cb
(
null
,
user
);
}
const
newUser
=
await
User
.
create
({
email
,
name
,
facebookId
:
id
,
avatarUrl
:
`https://graph.facebook.com/
${
id
}
/picture?type=large`
,
});
return
cb
(
null
,
newUser
);
}
catch
(
error
)
{
return
cb
(
error
,
null
);
}
// console.log(accessToken, refreshToken, profile, cb);
};
export
const
postFacebookLogin
=
(
req
,
res
)
=>
{
...
...
package.json
View file @
6aa7694
...
...
@@ -6,7 +6,8 @@
"scripts"
:
{
"dev:server"
:
"nodemon --exec babel-node init.js --delay 2 --ignore 'scss'"
,
"dev:assets"
:
"WEBPACK_ENV=development webpack -w"
,
"build:assets"
:
"WEBPACK_ENV=production webpack"
"build:assets"
:
"WEBPACK_ENV=production webpack"
,
"tunnel"
:
"ngrok http 80"
},
"repository"
:
{
"type"
:
"git"
,
...
...
@@ -33,6 +34,7 @@
"mongoose"
:
"^5.9.15"
,
"morgan"
:
"^1.10.0"
,
"multer"
:
"^1.4.2"
,
"ngrok"
:
"^3.2.7"
,
"node-sass"
:
"^4.14.1"
,
"passport"
:
"^0.4.1"
,
"passport-facebook"
:
"^3.0.0"
,
...
...
passport.js
View file @
6aa7694
...
...
@@ -30,7 +30,9 @@ passport.use(
{
clientID
:
process
.
env
.
FB_ID
,
clientSecret
:
process
.
env
.
FB_SECRET
,
callbackURL
:
`http://localhost:80
${
routes
.
facebookCallback
}
`
,
callbackURL
:
`https://77aa7153bcce.ngrok.io
${
routes
.
facebookCallback
}
`
,
profileFields
:
[
"id"
,
"displayName"
,
"photos"
,
"email"
],
scope
:
[
"public_profile"
,
"email"
],
},
facebookLoginCallback
)
...
...
Please
register
or
login
to post a comment