From 8d26be8abaca70d66414ec8a6afd078d3d10783b Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Wed, 23 Mar 2016 02:07:15 +0300 Subject: [PATCH] + core auth (authorizeUser) --- services/Instagram/src/core/auth.js | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 services/Instagram/src/core/auth.js diff --git a/services/Instagram/src/core/auth.js b/services/Instagram/src/core/auth.js new file mode 100644 index 00000000..1fc23d9b --- /dev/null +++ b/services/Instagram/src/core/auth.js @@ -0,0 +1,36 @@ +import {collection} from './db'; + +/** + * { + * username: String, + * bio: String, + * website: String, + * profile_picture: String, + * full_name: String, + * id: String + * } + * + * @param accessToken + * @param user + */ +export async function authorizeUser(accessToken, user) { + const provider = 'instagram'; + const users = collection('users'); + + let profile = await users.findOne({ + provider: provider, + username: user.username + }); + + if(profile){ + Object.keys(user).forEach(i => { + profile[i] = user[i]; + }); + profile.accessToken = accessToken; + + await users.update({_id: profile['_id']}, profile); + return profile; + }else{ + return null; + } +}