-
Notifications
You must be signed in to change notification settings - Fork 402
/
Copy pathtouch-session.ts
40 lines (38 loc) · 1.01 KB
/
touch-session.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
import { IncomingMessage, ServerResponse } from 'http';
import { NextApiRequest, NextApiResponse } from 'next';
import { SessionCache } from '../session';
import { assertReqRes } from '../utils/assert';
/**
* Touch the session object. If rolling sessions are enabled and autoSave is disabled, you will need
* to call this method to update the session expiry.
*
* ```js
* // pages/api/graphql.js
* import { touchSession } from '@auth0/nextjs-auth0';
*
* export default async function graphql(req, res) {
* await touchSession(req, res);
*
* // ...
* };
* ```
*
* @category Server
*/
export type TouchSession = (
req: IncomingMessage | NextApiRequest,
res: ServerResponse | NextApiResponse
) => Promise<void>;
/**
* @ignore
*/
export default function touchSessionFactory(sessionCache: SessionCache): TouchSession {
return async (req, res) => {
assertReqRes(req, res);
const session = await sessionCache.get(req, res);
if (!session) {
return;
}
await sessionCache.save(req, res);
};
}