-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
52 lines (46 loc) · 1.18 KB
/
app.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
40
41
42
43
44
45
46
47
48
49
50
51
52
const express = require("express"),
api = require("auth0").ManagementClient,
cors = require("cors"),
app = express(),
port = process.env.PORT;
app.use(express.json());
app.use(cors({
origin: "https://userlist-one.vercel.app",
optionsSuccessStatus: 200
}));
const { users } = new api({
domain: process.env.DOMAIN,
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET
});
app.get("/", (req, res) => {
let params = {
per_page: 10,
...req.query,
include_totals: true,
fields: "user_id,name,email,created_at,last_login,blocked",
include_fields: true
};
users.getAll(params)
.then(users => res.status(200).json(users))
.catch(({ statusCode }) => res.sendStatus(statusCode));
});
app.patch("/", (req, res) => {
let { userIds, blocked } = req.body;
userIds.map(id => {
users.update({ id }, { blocked })
.catch(err => null);
})
res.sendStatus(204);
});
app.delete("/", (req, res) => {
let userIds = req.body;
userIds.map(id => {
users.delete({ id })
.catch(err => null)
})
res.sendStatus(204);
});
app.listen(port, () => {
console.log("App listening on port " + port);
});