-
Notifications
You must be signed in to change notification settings - Fork 0
/
createFirstUser.js
44 lines (39 loc) · 935 Bytes
/
createFirstUser.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
const crypto = require('crypto');
const randomString = () => crypto.randomBytes(6).hexSlice();
const createFirstUser = async (keystone) => {
const {
data: {
_allUsersMeta: { count },
},
} = await keystone.executeQuery(
`query {
_allUsersMeta {
count
}
}`
);
if (count === 0) {
const password = randomString();
const email = 'admin@example.com';
await keystone.executeQuery(
`mutation initialUser($password: String, $email: String) {
createUser(data: {name: "Admin", email: $email, isAdmin: true, password: $password}) {
id
}
}`,
{
variables: {
password,
email,
},
}
);
console.log(`
User created:
email: ${email}
password: ${password}
Please change these details after initial login.
`);
}
}
module.exports = createFirstUser