AI Resource Pro / website / test-auth-bypass.js
| 1 | // Simple script to test environment variables access |
| 2 | import * as dotenv from 'dotenv'; |
| 3 | import { fileURLToPath } from 'url'; |
| 4 | import { dirname, join } from 'path'; |
| 5 | |
| 6 | // Get current directory |
| 7 | const __filename = fileURLToPath(import.meta.url); |
| 8 | const __dirname = dirname(__filename); |
| 9 | |
| 10 | // Load environment variables from .env.local |
| 11 | dotenv.config({ path: join(__dirname, '.env.local') }); |
| 12 | |
| 13 | console.log("Testing environment variables:"); |
| 14 | console.log("NODE_ENV:", process.env.NODE_ENV); |
| 15 | console.log("BYPASS_AUTH_IN_DEV exists:", !!process.env.BYPASS_AUTH_IN_DEV); |
| 16 | console.log("BYPASS_AUTH_IN_DEV value:", process.env.BYPASS_AUTH_IN_DEV); |
| 17 | console.log("NEXT_PUBLIC_AI_RESOURCE_PRO_API_KEY exists:", !!process.env.NEXT_PUBLIC_AI_RESOURCE_PRO_API_KEY); |
| 18 | if (process.env.NEXT_PUBLIC_AI_RESOURCE_PRO_API_KEY) { |
| 19 | console.log("NEXT_PUBLIC_AI_RESOURCE_PRO_API_KEY length:", process.env.NEXT_PUBLIC_AI_RESOURCE_PRO_API_KEY.length); |
| 20 | console.log("NEXT_PUBLIC_AI_RESOURCE_PRO_API_KEY first 5 chars:", process.env.NEXT_PUBLIC_AI_RESOURCE_PRO_API_KEY.substring(0, 5)); |
| 21 | console.log("NEXT_PUBLIC_AI_RESOURCE_PRO_API_KEY last 5 chars:", process.env.NEXT_PUBLIC_AI_RESOURCE_PRO_API_KEY.substring(process.env.AI_RESOURCE_PRO_API_KEY.length - 5)); |
| 22 | } |
| 23 | |
| 24 | // Simulate the validation check |
| 25 | const isDevMode = process.env.NODE_ENV === 'development'; |
| 26 | const bypassAuthInDev = process.env.BYPASS_AUTH_IN_DEV === 'true'; |
| 27 | |
| 28 | console.log("\nAuth bypass simulation:"); |
| 29 | console.log("Is development mode?", isDevMode); |
| 30 | console.log("Should bypass auth?", bypassAuthInDev); |
| 31 | console.log("Auth would be bypassed?", isDevMode && bypassAuthInDev); |
| 32 | |
| 33 | console.log("\nIf 'Auth would be bypassed?' is false, check your .env.local and ensure:"); |
| 34 | console.log("1. NODE_ENV is set to 'development'"); |
| 35 | console.log("2. BYPASS_AUTH_IN_DEV is set to 'true'"); |