-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeystone.ts
60 lines (56 loc) · 1.64 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
import { createAuth } from "@keystone-6/auth";
import { config } from "@keystone-6/core";
import { statelessSessions } from "@keystone-6/core/session";
import { config as envConfig } from "dotenv";
import { authConfig, lists } from "./keystone/schema";
const { withAuth } = createAuth(authConfig);
envConfig({ path: ["./.env", "./.env.local"] });
const session = statelessSessions({
secret: process.env.AUTH_SECRET,
maxAge: 60 * 60 * 24 * 30,
});
const _start = session.start;
session.start = function (...args) {
if (!args[0].context?.res)
return Promise.resolve("hooks.session.start from nextauth.js");
return _start.call(this, ...args);
};
export default withAuth(
config({
server: {
port: 4000,
},
db: {
provider: "postgresql",
url: process.env.POSTGRES_URL!,
enableLogging: false,
prismaClientPath: "node_modules/.prisma/client",
},
lists,
session: session,
ui: {
// the following api routes are required for nextauth.js
publicPages: [
"/api/auth/csrf",
"/api/auth/signin",
"/api/auth/callback",
"/api/auth/session",
"/api/auth/providers",
"/api/auth/signout",
"/api/auth/error",
// each provider will need a separate callback and signin page listed here
"/api/auth/signin/github",
"/api/auth/callback/github",
],
// adding page middleware ensures that users are redirected to the signin page if they are not signed in.
// pageMiddleware: async ({ wasAccessAllowed }) => {
// if (wasAccessAllowed) return;
// return {
// kind: "redirect",
// to: "/api/auth/signin",
// };
// },
isAccessAllowed: (context) => !!context.session?.data?.isAdmin,
},
}),
);