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,5 +1,6 @@
import { NextApiResponse } from 'next';
import { openaiError, openaiError2, proxyError, ERROR_RESPONSE, ERROR_ENUM } from './errorCode';
import { clearCookie } from './utils/tools';
export interface ResponseType<T = any> {
code: number;
@@ -23,7 +24,7 @@ export const jsonRes = <T = any>(
if (ERROR_RESPONSE[errResponseKey]) {
// login is expired
if (errResponseKey === ERROR_ENUM.unAuthorization) {
res.setHeader('Set-Cookie', 'token=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT');
clearCookie(res);
}
return res.json(ERROR_RESPONSE[errResponseKey]);