mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-21 03:35:36 +00:00

* add prelogin api (#4762) * add prelogin api * move type.d.ts * perf: prelogin code * doc * fix: ts --------- Co-authored-by: dreamer6680 <1468683855@qq.com>
64 lines
1.1 KiB
TypeScript
64 lines
1.1 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';
|
|
|
|
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(i18nT('common:error.code_error'));
|
|
}
|
|
|
|
await result.deleteOne({ session });
|
|
|
|
return 'SUCCESS';
|
|
});
|
|
};
|