-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsession.ts
More file actions
52 lines (46 loc) · 1.21 KB
/
session.ts
File metadata and controls
52 lines (46 loc) · 1.21 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
import { Application } from "express";
import expressSession from 'express-session';
import { PrismaSessionStore } from "@quixo3/prisma-session-store";
import prisma from '../prisma/prisma';
import type { IPrisma } from "@quixo3/prisma-session-store/dist/@types";
import type { PrismaClient } from "@prisma/client";
import 'dotenv/config';
declare module 'express-session' {
interface SessionData {
passport?: {
user: {
id: number,
name: string,
username: string,
passowrd: string,
email: string,
join_date: string
}
}
}
}
const store: PrismaSessionStore<"session"> = new PrismaSessionStore(
prisma as PrismaClient & IPrisma<"session">,
{
checkPeriod: 2 * 60 * 1000, //ms
dbRecordIdIsSessionId: true
}
);
const secure = process.env.NODE_ENV === 'prod' ? true : false;
const generateSession = (app: Application) => {
app.use(
expressSession({
secret: process.env.SESSION_SECRET as string,
cookie: {
maxAge: 30 * 24 * 60 * 60 * 1000,
secure,
httpOnly: secure,
sameSite: 'none'
},
saveUninitialized: false,
resave: false,
store
})
);
}
export default generateSession;