-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.ts
27 lines (22 loc) · 740 Bytes
/
auth.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
import { randomBytes } from "crypto";
import { createAuth } from "@keystone-6/auth";
import { statelessSessions } from "@keystone-6/core/session";
let sessionSecret = process.env.SESSION_SECRET;
if (!sessionSecret && process.env.NODE_ENV !== "production") {
sessionSecret = randomBytes(32).toString("hex");
}
const { withAuth } = createAuth({
listKey: "User",
identityField: "username",
sessionData: "id username role permissions isBlocked",
secretField: "password",
initFirstItem: {
fields: ["username", "firstname", "role", "email", "password"],
},
});
const sessionMaxAge = 60 * 60 * 24 * 30;
const session = statelessSessions({
maxAge: sessionMaxAge,
secret: sessionSecret!,
});
export { withAuth, session };