perf: auth token

This commit is contained in:
archer
2023-04-29 15:59:53 +08:00
parent 78762498eb
commit ea100d84bf
35 changed files with 38 additions and 52 deletions

View File

@@ -23,25 +23,6 @@ export const generateToken = (userId: string) => {
return token;
};
/* 校验 token */
export const authToken = (token?: string): Promise<string> => {
return new Promise((resolve, reject) => {
if (!token) {
reject('缺少登录凭证');
return;
}
const key = process.env.TOKEN_KEY as string;
jwt.verify(token, key, function (err, decoded: any) {
if (err || !decoded?.userId) {
reject('凭证无效');
return;
}
resolve(decoded.userId);
});
});
};
/* openai axios config */
export const axiosConfig = () => ({
httpsAgent: global.httpsAgent,