-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeystone.ts
90 lines (83 loc) · 2.28 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
80
81
82
83
84
85
86
87
88
89
90
import { createAuth } from '@keystone-next/auth';
import 'dotenv/config';
import { User } from './schemas/User';
import { Product } from './schemas/Product';
import { ProductImage } from './schemas/ProductImage';
import { CartItem } from './schemas/CartItem';
import { OrderItem } from './schemas/OrderItem';
import { Order } from './schemas/Order';
import { Role } from './schemas/Role';
import { permissionsList } from './schemas/Fields';
import { config, list } from '@keystone-6/core';
import type {
ListSchemaConfig,
ServerConfig,
DatabaseConfig,
AdminUIConfig,
SessionStrategy,
} from '@keystone-6/core/types';
import { statelessSessions } from '@keystone-next/keystone/session';
// import { insertSeedData } from './seed-data/index';
import { postgresql } from '@keystone-next/keystone/dist/declarations/src/types/filters';
import { extendGraphqlSchema } from './mutations';
import { sendPasswordResetEmail } from './lib/mail';
const databaseURL = process.env.DATABASE_URL || 'postgres://admin:adminpassword@localhost/brassmart';
const db = {
provider: 'postgresql',
url: databaseURL,
onConnect: async context => {
console.log(`Front-end URL: ${process.env.FRONTEND_URL}`);
// console.log(context);
// if (process.argv.includes('--seed-data')) {
// await insertSeedData(keystone);
// }
},
};
const sessionConfig = {
maxAge: 60 * 60 * 24 * 30,
secret: process.env.SESSION_SECRET,
secure: true,
sameSite: 'none',
}
const { withAuth } = createAuth({
listKey: 'User',
identityField: 'email',
secretField: 'password',
initFirstItem: {
fields: ['name', 'email', 'password'],
// TODO: add in intial roles
},
sessionData: `id name email role { ${permissionsList.join(' ')} }`,
passwordResetLink: {
async sendToken(args) {
await sendPasswordResetEmail(args.token, args.identity)
},
},
});
const lists = {
User,
Product,
ProductImage,
CartItem,
OrderItem,
Order,
Role,
};
export default withAuth(
config({
server: {
cors: {
origin: [process.env.FRONTEND_URL],
credentials: true,
},
},
db,
lists,
extendGraphqlSchema,
ui: {
// TODO: change for roles
isAccessAllowed: ({ session }) => !!session?.data
},
session: statelessSessions(sessionConfig)
}),
);