mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 16:23:41 +08:00 
			
		
		
		
	feat: close #813 log user ip time
This commit is contained in:
		@@ -8,6 +8,17 @@ export const config = {
 | 
			
		||||
 | 
			
		||||
const serverConfig = getServerSideConfig();
 | 
			
		||||
 | 
			
		||||
function getIP(req: NextRequest) {
 | 
			
		||||
  let ip = req.ip ?? req.headers.get("x-real-ip");
 | 
			
		||||
  const forwardedFor = req.headers.get("x-forwarded-for");
 | 
			
		||||
 | 
			
		||||
  if (!ip && forwardedFor) {
 | 
			
		||||
    ip = forwardedFor.split(",").at(0) ?? "";
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return ip;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function middleware(req: NextRequest) {
 | 
			
		||||
  const accessCode = req.headers.get("access-code");
 | 
			
		||||
  const token = req.headers.get("token");
 | 
			
		||||
@@ -16,6 +27,8 @@ export function middleware(req: NextRequest) {
 | 
			
		||||
  console.log("[Auth] allowed hashed codes: ", [...serverConfig.codes]);
 | 
			
		||||
  console.log("[Auth] got access code:", accessCode);
 | 
			
		||||
  console.log("[Auth] hashed access code:", hashedCode);
 | 
			
		||||
  console.log("[User IP] ", getIP(req));
 | 
			
		||||
  console.log("[Time] ", new Date().toLocaleString());
 | 
			
		||||
 | 
			
		||||
  if (serverConfig.needCode && !serverConfig.codes.has(hashedCode) && !token) {
 | 
			
		||||
    return NextResponse.json(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user