Commit 6e6b026d by Archer Committed by GitHub

fix: auth code secret (#6662)

parent 34c85ad5
import type { UserAuthTypeEnum } from '@fastgpt/global/support/user/auth/constants'; import { UserAuthTypeEnum } from '@fastgpt/global/support/user/auth/constants';
import { MongoUserAuth } from './schema'; import { MongoUserAuth } from './schema';
import { i18nT } from '../../../../web/i18n/utils'; import { i18nT } from '../../../../web/i18n/utils';
import { mongoSessionRun } from '../../../common/mongo/sessionRun'; import { mongoSessionRun } from '../../../common/mongo/sessionRun';
import { UserError } from '@fastgpt/global/common/error/utils'; import { UserError } from '@fastgpt/global/common/error/utils';
import { z } from 'zod';
export const addAuthCode = async ({ export const addAuthCode = async ({
key, key,
...@@ -33,15 +34,13 @@ export const addAuthCode = async ({ ...@@ -33,15 +34,13 @@ export const addAuthCode = async ({
); );
}; };
export const authCode = async ({ const authCodeSchema = z.object({
key, key: z.string(),
type, type: z.enum(UserAuthTypeEnum),
code code: z.string()
}: { });
key: string; export const authCode = async (props: z.infer<typeof authCodeSchema>) => {
type: `${UserAuthTypeEnum}`; const { key, type, code } = authCodeSchema.parse(props);
code: string;
}) => {
return mongoSessionRun(async (session) => { return mongoSessionRun(async (session) => {
const result = await MongoUserAuth.findOne( const result = await MongoUserAuth.findOne(
{ {
......
import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next'; import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next';
import { NextAPI } from '@/service/middleware/entry'; import { NextAPI } from '@/service/middleware/entry';
import type { import type {
ApiKeyHealthParamsType,
ApiKeyHealthResponseType ApiKeyHealthResponseType
} from '@fastgpt/global/openapi/support/openapi/api'; } from '@fastgpt/global/openapi/support/openapi/api';
import {
ApiKeyHealthParamsSchema
} from '@fastgpt/global/openapi/support/openapi/api';
import { MongoOpenApi } from '@fastgpt/service/support/openapi/schema'; import { MongoOpenApi } from '@fastgpt/service/support/openapi/schema';
import { useIPFrequencyLimit } from '../../../../../../../packages/service/common/middle/reqFrequencyLimit'; import { useIPFrequencyLimit } from '../../../../../../../packages/service/common/middle/reqFrequencyLimit';
export type invalidBody = {};
async function handler( async function handler(
req: ApiRequestProps<invalidBody, ApiKeyHealthParamsType>, req: ApiRequestProps,
res: ApiResponseType<any> res: ApiResponseType<any>
): Promise<ApiKeyHealthResponseType> { ): Promise<ApiKeyHealthResponseType> {
const { apiKey } = req.query; const { apiKey } = ApiKeyHealthParamsSchema.parse(req.query);
const apiKeyDoc = await MongoOpenApi.findOne({ apiKey }).lean(); const apiKeyDoc = await MongoOpenApi.findOne({ apiKey }).lean();
if (!apiKeyDoc) { if (!apiKeyDoc) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment