-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
51 lines (45 loc) · 1.31 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
const { Keystone, PasswordAuthStrategy } = require("@keystone-alpha/keystone");
const { GraphQLApp } = require("@keystone-alpha/app-graphql");
const { AdminUIApp } = require("@keystone-alpha/app-admin-ui");
const { StaticApp } = require("@keystone-alpha/app-static");
const {
MongooseAdapter: Adapter
} = require("@keystone-alpha/adapter-mongoose");
const keystone = new Keystone({
name: "Role based access demo",
adapter: new Adapter(),
onConnect: async keystone => {
const users = await keystone.lists.User.adapter.findAll();
if (!users.length) {
await keystone.createItems({
User: [
{
name: "Admin",
email: "[email protected]",
isAdmin: true,
password: "12345678"
}
]
});
}
}
});
const { User } = require("./user");
const { Role } = require("./role");
const { Post } = require("./post");
keystone.createList("User", User);
keystone.createList("Role", Role);
keystone.createList("Post", Post);
const authStrategy = keystone.createAuthStrategy({
type: PasswordAuthStrategy,
list: "User"
});
module.exports = {
keystone,
apps: [
new GraphQLApp(),
new StaticApp({ path: "/", src: "public" }),
// Setup the optional Admin UI
new AdminUIApp({ enableDefaultRoute: true, authStrategy })
]
};