feat: cookie expired time

This commit is contained in:
archer
2023-05-09 11:26:11 +08:00
parent de6ac0f589
commit b200731d17
5 changed files with 18 additions and 7 deletions

View File

@@ -1,3 +1,4 @@
import type { NextApiResponse } from 'next';
import crypto from 'crypto';
import jwt from 'jsonwebtoken';
@@ -19,6 +20,15 @@ export const generateToken = (userId: string) => {
return token;
};
/* set cookie */
export const setCookie = (res: NextApiResponse, userId: string) => {
res.setHeader('Set-Cookie', `token=${generateToken(userId)}; Path=/; HttpOnly; Max-Age=604800`);
};
/* clear cookie */
export const clearCookie = (res: NextApiResponse) => {
res.setHeader('Set-Cookie', 'token=; Path=/; Max-Age=0');
};
/* openai axios config */
export const axiosConfig = () => ({
httpsAgent: global.httpsAgent,