diff --git a/next.config.ts b/next.config.ts index 92ecea6..8bc65ef 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,9 +1,16 @@ import type { NextConfig } from "next"; +import os from "os"; + +// Автоопределение LAN IP для dev — убирает "Blocked cross-origin" без ручной настройки +const lanIPs = Object.values(os.networkInterfaces()) + .flat() + .filter((iface) => iface && !iface.internal && iface.family === "IPv4") + .map((iface) => iface!.address); const nextConfig: NextConfig = { output: "standalone", serverExternalPackages: ["@prisma/client", "bcryptjs", "ioredis"], - allowedDevOrigins: ["192.168.1.78"], + allowedDevOrigins: lanIPs, }; export default nextConfig; diff --git a/setup.sh b/setup.sh index b8f921b..f03df6c 100644 --- a/setup.sh +++ b/setup.sh @@ -1377,17 +1377,6 @@ cmd_dev() { log_warn "MinIO ещё не готов — bucket создастся при следующем запуске" fi - # Автоопределение LAN IP для auth - local lan_ip - lan_ip=$(hostname -I 2>/dev/null | awk '{print $1}' || true) - if [[ -n "$lan_ip" && -z "$(env_get LAN_HOST)" ]]; then - log_info "LAN IP: ${lan_ip}" - if ! grep -q "^LAN_HOST=" .env 2>/dev/null; then - echo "LAN_HOST=${lan_ip}" >> .env - log_ok "LAN_HOST=${lan_ip} добавлен в .env" - fi - fi - # Запуск echo "" log_ok "${GREEN}${BOLD}Готово! Запускаю dev-сервер...${NC}" diff --git a/src/lib/auth.ts b/src/lib/auth.ts index cbed08b..ba497d0 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -1,24 +1,29 @@ import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import { prisma } from "./prisma"; +import os from "os"; function getTrustedOrigins(): string[] { + // Prod: явный список origins if (process.env.BETTER_AUTH_TRUSTED_ORIGINS) { return process.env.BETTER_AUTH_TRUSTED_ORIGINS.split(",").map((o) => o.trim()); } - // Без явной конфигурации — разрешаем localhost на типичных портах Next.js - const origins: string[] = []; - for (let port = 3000; port <= 3010; port++) { - origins.push(`http://localhost:${port}`); - origins.push(`http://127.0.0.1:${port}`); + // Dev: автоопределение всех IP машины — работает с любого адреса без настройки + const hosts = new Set(["localhost", "127.0.0.1"]); + + for (const ifaces of Object.values(os.networkInterfaces())) { + for (const iface of ifaces ?? []) { + if (!iface.internal && iface.family === "IPv4") { + hosts.add(iface.address); + } + } } - // LAN-доступ: если задан LAN_HOST (IP сервера в локальной сети) - const lanHost = process.env.LAN_HOST; - if (lanHost) { + const origins: string[] = []; + for (const host of hosts) { for (let port = 3000; port <= 3010; port++) { - origins.push(`http://${lanHost}:${port}`); + origins.push(`http://${host}:${port}`); } }