Repository navigation
Expand file tree
/
Copy pathkeystone.ts
More file actions
67 lines (62 loc) · 1.86 KB
/
Copy pathkeystone.ts
File metadata and controls
67 lines (62 loc) · 1.86 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { config } from '@keystone-6/core';
import { statelessSessions } from '@keystone-6/core/session';
import { createAuth } from '@keystone-6/auth';
import { lists, extendGraphqlSchema } from './schema';
let sessionSecret = '-- DEV COOKIE SECRET; CHANGE ME --';
let sessionMaxAge = 60 * 60 * 24 * 30; // 30 days
const auth = createAuth({
listKey: 'User',
identityField: 'email',
secretField: 'password',
initFirstItem: {
fields: ['name', 'email', 'password'],
itemData: {
isAdmin: true,
},
},
sessionData: 'name isAdmin',
});
// TODO -- Create a separate example for access control in the Admin UI
// const isAccessAllowed = ({ session }: { session: any }) => !!session?.item?.isAdmin;
export default auth.withAuth(
config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',
},
ui: {
// NOTE -- this is not implemented, keystone currently always provides an admin ui at /
// path: '/admin',
// isAccessAllowed,
},
storage: {
my_images: {
kind: 'local',
type: 'file',
storagePath: 'public/images',
generateUrl: path => `http://localhost:3000/images${path}`,
serverRoute: {
path: '/images',
},
},
my_files: {
kind: 'local',
type: 'file',
storagePath: 'public/files',
generateUrl: path => `http://localhost:3000/files${path}`,
serverRoute: {
path: '/files',
},
},
},
lists,
extendGraphqlSchema,
session: statelessSessions({ maxAge: sessionMaxAge, secret: sessionSecret }),
// TODO -- Create a separate example for stored/redis sessions
// session: storedSessions({
// store: new Map(),
// // store: redisSessionStore({ client: redis.createClient() }),
// secret: sessionSecret,
// }),
})
);