aboutsummaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2019-01-10 20:39:58 -0800
committerAdam Soltys <[email protected]>2019-02-05 20:53:45 -0800
commit3fe77ca010a1946b77fdb5288dd7a628f80cadeb (patch)
tree5e6a69b08795ae8d012700e58e20daac4f513274 /index.js
parentdb1f0b681fecf82ffddbf7809bcadab93db4d9f5 (diff)
downloadcoinos-server-3fe77ca010a1946b77fdb5288dd7a628f80cadeb.tar.gz
coinos-server-3fe77ca010a1946b77fdb5288dd7a628f80cadeb.zip
/friends endpoint
Diffstat (limited to 'index.js')
-rw-r--r--index.js20
1 files changed, 19 insertions, 1 deletions
diff --git a/index.js b/index.js
index 5576aa5b..33270d09 100644
--- a/index.js
+++ b/index.js
@@ -388,6 +388,21 @@ const l = console.log
})
})
+ app.get('/friends', auth, async (req, res) => {
+ try {
+ let friends = (await fb.api(`/${req.user.username}/friends?access_token=${req.user.fbtoken}`)).data
+ friends = await Promise.all(friends.map(async f => {
+ let pic = (await fb.api(`/${f.id}/picture?redirect=false&type=small&accessToken=${req.user.fbtoken}`)).data
+ f.pic = pic.url
+ return f
+ }))
+
+ res.send(friends)
+ } catch (e) {
+ res.status(500).send('There was a problem getting your facebook friends: ', e)
+ }
+ })
+
app.post('/payUser', auth, async (req, res) => {
let { payuser, amount } = req.body
@@ -397,7 +412,7 @@ const l = console.log
}
})
- if (!user) return res.status(401).end()
+ if (!user) return res.status(401).send("Couldn't find the user you're trying to pay")
let err = m => res.status(500).send(m)
let invoice
@@ -576,6 +591,9 @@ const l = console.log
addresses[user.address] = user.username
}
+ user.fbtoken = accessToken
+ await user.save()
+
let payload = { username: user.username }
let token = jwt.sign(payload, process.env.SECRET)
res.cookie('token', token, { expires: new Date(Date.now() + 432000000) })