feat: auto LAN auth + setup.sh dev command
- auth.ts: auto-allow localhost:3000-3010 + LAN_HOST for trustedOrigins - setup.sh: new `dev` command (update + kill old processes + auto LAN IP + launch) - next.config.ts: allowedDevOrigins for LAN HMR
This commit is contained in:
@@ -2,11 +2,32 @@ import { betterAuth } from "better-auth";
|
||||
import { prismaAdapter } from "better-auth/adapters/prisma";
|
||||
import { prisma } from "./prisma";
|
||||
|
||||
function getTrustedOrigins(): string[] {
|
||||
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}`);
|
||||
}
|
||||
|
||||
// LAN-доступ: если задан LAN_HOST (IP сервера в локальной сети)
|
||||
const lanHost = process.env.LAN_HOST;
|
||||
if (lanHost) {
|
||||
for (let port = 3000; port <= 3010; port++) {
|
||||
origins.push(`http://${lanHost}:${port}`);
|
||||
}
|
||||
}
|
||||
|
||||
return origins;
|
||||
}
|
||||
|
||||
export const auth = betterAuth({
|
||||
baseURL: process.env.BETTER_AUTH_URL,
|
||||
trustedOrigins: process.env.BETTER_AUTH_TRUSTED_ORIGINS
|
||||
? process.env.BETTER_AUTH_TRUSTED_ORIGINS.split(",")
|
||||
: ["http://localhost:3000"],
|
||||
trustedOrigins: getTrustedOrigins(),
|
||||
database: prismaAdapter(prisma, {
|
||||
provider: "postgresql",
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user