-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (32 loc) · 956 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import express from 'express'
import fetch from 'node-fetch'
const PORT = process.env.PORT || 2000
const app = express();
app.use(express.json());
const getProfileInfo = (user_id) => {
const headers = {
Authorization: 'Bearer ' + process.env.AUTH_MANAGEMENT_API_TOKEN,
};
console.log(headers);
return fetch(
'https://' + process.env.AUTH0_DOMAIN + '/api/v2/users/' + user_id,
{ headers: headers }
).then((response) => response.json());
};
app.post('/auth0', async (req, res) => {
const { session_variables } = req.body;
const user_id = session_variables['x-hasura-user-id']
return getProfileInfo(user_id).then(function (resp) {
console.log(resp)
if (!resp) {
return res.status(400).json({
message: "error happened"
})
}
return res.json({
email: resp.email,
picture: resp.picture
})
})
})
app.listen(PORT)