Created
October 24, 2017 16:35
-
-
Save leejh3224/1b720a54c987fe9924df0ded8329beb7 to your computer and use it in GitHub Desktop.
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
/* naver */ | |
passport.use('provider:naver', new NaverStrategy({ | |
clientID: naver.clientID, | |
clientSecret: naver.clientSecret, | |
callbackURL: naver.callbackURL, | |
}, (accessToken, refreshToken, profile, done) => { | |
User.findOne({ 'social.naver.id': profile.id }) | |
.then(user => { | |
if (!user) { | |
const newUser = new User() | |
/* | |
* 당연한 얘기일수 있지만 이 경우 newUser.access_token 이런 식으로 | |
* 저장하려고 하면 에러 메시지 없이 저장이 안 된다. | |
*/ | |
const newUser = new User() | |
newUser.social.naver.access_token = accessToken | |
newUser.social.naver.id = profile.id | |
newUser.social.naver.displayName = profile.displayName | |
return newUser.save() | |
.then(user => done(null, user)) | |
.catch(e => done(e, false)) | |
} | |
return done(null, user) | |
}) | |
.catch(e => done(e, false)) | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment