Files
FastGPT/packages/service/support/user/auth/controller.ts
T
Archer 9959707fb3 V4.14.9 fix issue (#6573)
* fix: session error

* fix: session error

* fix: workflow runtime and add e2b
2026-03-19 11:15:14 +08:00

65 lines
1.2 KiB
TypeScript

import type { UserAuthTypeEnum } from '@fastgpt/global/support/user/auth/constants';
import { MongoUserAuth } from './schema';
import { i18nT } from '../../../../web/i18n/utils';
import { mongoSessionRun } from '../../../common/mongo/sessionRun';
import { UserError } from '@fastgpt/global/common/error/utils';
export const addAuthCode = async ({
key,
code,
openid,
type,
expiredTime
}: {
key: string;
code?: string;
openid?: string;
type: `${UserAuthTypeEnum}`;
expiredTime?: Date;
}) => {
return MongoUserAuth.updateOne(
{
key,
type
},
{
code,
openid,
expiredTime
},
{
upsert: true
}
);
};
export const authCode = async ({
key,
type,
code
}: {
key: string;
type: `${UserAuthTypeEnum}`;
code: string;
}) => {
return mongoSessionRun(async (session) => {
const result = await MongoUserAuth.findOne(
{
key,
type,
code: { $regex: new RegExp(`^${code}$`, 'i') }
},
undefined,
{ session }
);
if (!result) {
return Promise.reject(new UserError(i18nT('common:error.code_error')));
}
await result.deleteOne();
return 'SUCCESS';
});
};