-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeystone.ts
79 lines (74 loc) · 2.03 KB
/
keystone.ts
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
68
69
70
71
72
73
74
75
76
77
78
79
import { createAuth } from '@keystone-next/auth';
import { config, createSchema } from '@keystone-next/keystone/schema';
import {
withItemData,
statelessSessions,
} from '@keystone-next/keystone/session';
import { Role } from './schemas/Role';
import { OrderItem } from './schemas/OrderItem';
import { Order } from './schemas/Order';
import { User } from './schemas/User';
import 'dotenv/config';
import { Product } from './schemas/Product';
import { ProductImage } from './schemas/ProductImage';
import { insertSeedData } from './seed-data';
import { sendPasswordResetEmail } from './lib/mail';
import { CartItem } from './schemas/CartItem';
import { extendGraphqlSchema } from './mutations';
import { permissionsList } from './schemas/fields';
const databaseURL = process.env.MONGO_URI;
const sessionConfig = {
maxAge: 60 * 60 * 24 * 360,
secret: process.env.COOKIE_SECRET,
};
const { withAuth } = createAuth({
listKey: 'User',
identityField: 'email',
secretField: 'password',
initFirstItem: {
fields: ['name', 'email', 'password'],
},
passwordResetLink: {
async sendToken(args) {
await sendPasswordResetEmail(args.token, args.identity);
},
},
});
export default withAuth(
config({
server: {
cors: {
origin: ['https://www.acuteangle.us'],
// origin: [process.env.FRONTEND_URL],
credentials: true,
},
},
db: {
adapter: 'mongoose',
url: databaseURL,
async onConnect(keystone) {
console.log('Connected to the database.');
/* if (process.argv.includes('--seed-data')) {
await insertSeedData(keystone);
} */
},
},
lists: createSchema({
// schema items go here
User,
Product,
ProductImage,
CartItem,
OrderItem,
Order,
Role,
}),
extendGraphqlSchema,
ui: {
isAccessAllowed: ({ session }) => !!session?.data,
},
session: withItemData(statelessSessions(sessionConfig), {
User: `id name email role { ${permissionsList.join(' ')} }`,
}),
})
);