-
Notifications
You must be signed in to change notification settings - Fork 408
/
Copy pathtouch-session.ts
38 lines (36 loc) · 1.07 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
import { IncomingMessage, ServerResponse } from 'http';
import { NextApiRequest, NextApiResponse } from 'next';
import { NextRequest, NextResponse } from 'next/server';
import { get, set, SessionCache } from '../session';
/**
* 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 = (
...args: [IncomingMessage, ServerResponse] | [NextApiRequest, NextApiResponse] | [NextRequest, NextResponse] | []
) => Promise<void>;
/**
* @ignore
*/
export default function touchSessionFactory(sessionCache: SessionCache): TouchSession {
return async (req?, res?) => {
const [session, iat] = await get({ sessionCache, req, res });
if (!session) {
return;
}
await set({ req, res, session, sessionCache, iat });
};
}