mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 08:13:43 +08:00 
			
		
		
		
	Merge pull request #3617 from H0llyW00dzZ/fixfixbug
Fix [Bug] Issue ChatGPTNextWeb#3615
This commit is contained in:
		@@ -55,15 +55,18 @@ export function auth(req: NextRequest) {
 | 
			
		||||
 | 
			
		||||
  // if user does not provide an api key, inject system api key
 | 
			
		||||
  if (!apiKey) {
 | 
			
		||||
    const serverApiKey = serverConfig.isAzure
 | 
			
		||||
    const serverConfig = getServerSideConfig();
 | 
			
		||||
    const systemApiKey = serverConfig.isAzure
 | 
			
		||||
      ? serverConfig.azureApiKey
 | 
			
		||||
      : serverConfig.isGoogle
 | 
			
		||||
      ? serverConfig.googleApiKey
 | 
			
		||||
      : serverConfig.apiKey;
 | 
			
		||||
 | 
			
		||||
    if (serverApiKey) {
 | 
			
		||||
    if (systemApiKey) {
 | 
			
		||||
      console.log("[Auth] use system api key");
 | 
			
		||||
      req.headers.set(
 | 
			
		||||
        "Authorization",
 | 
			
		||||
        `${serverConfig.isAzure ? "" : "Bearer "}${serverApiKey}`,
 | 
			
		||||
        `Bearer ${systemApiKey}`,
 | 
			
		||||
      );
 | 
			
		||||
    } else {
 | 
			
		||||
      console.log("[Auth] admin did not provide an api key");
 | 
			
		||||
 
 | 
			
		||||
@@ -65,6 +65,7 @@ export const getServerSideConfig = () => {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const isAzure = !!process.env.AZURE_URL;
 | 
			
		||||
  const isGoogle = !!process.env.GOOGLE_API_KEY;
 | 
			
		||||
 | 
			
		||||
  const apiKeyEnvVar = process.env.OPENAI_API_KEY ?? "";
 | 
			
		||||
  const apiKeys = apiKeyEnvVar.split(",").map((v) => v.trim());
 | 
			
		||||
@@ -84,6 +85,7 @@ export const getServerSideConfig = () => {
 | 
			
		||||
    azureApiKey: process.env.AZURE_API_KEY,
 | 
			
		||||
    azureApiVersion: process.env.AZURE_API_VERSION,
 | 
			
		||||
 | 
			
		||||
    isGoogle,
 | 
			
		||||
    googleApiKey: process.env.GOOGLE_API_KEY,
 | 
			
		||||
    googleUrl: process.env.GOOGLE_URL,
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user