fix: auth not working when accessed from non-localhost
- Remove hardcoded baseURL from auth-client.ts — better-auth now uses current window.location.origin, works from any IP/domain - Add trustedOrigins config to auth.ts — allows requests from LAN IPs - Add BETTER_AUTH_TRUSTED_ORIGINS env var for configuring allowed origins - Improve error logging in login/register forms (was silent catch) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -25,8 +25,9 @@ export default function LoginPage() {
|
|||||||
} else {
|
} else {
|
||||||
router.push("/dashboard");
|
router.push("/dashboard");
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (err) {
|
||||||
setError("Произошла ошибка. Попробуйте ещё раз.");
|
console.error("Login error:", err);
|
||||||
|
setError(err instanceof Error ? err.message : "Произошла ошибка. Попробуйте ещё раз.");
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,9 @@ export default function RegisterPage() {
|
|||||||
} else {
|
} else {
|
||||||
router.push("/dashboard");
|
router.push("/dashboard");
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (err) {
|
||||||
setError("Произошла ошибка. Попробуйте ещё раз.");
|
console.error("Register error:", err);
|
||||||
|
setError(err instanceof Error ? err.message : "Произошла ошибка. Попробуйте ещё раз.");
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { createAuthClient } from "better-auth/react";
|
import { createAuthClient } from "better-auth/react";
|
||||||
|
|
||||||
export const authClient = createAuthClient({
|
export const authClient = createAuthClient();
|
||||||
baseURL: process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000",
|
|
||||||
});
|
|
||||||
|
|
||||||
export const { signIn, signUp, signOut, useSession } = authClient;
|
export const { signIn, signUp, signOut, useSession } = authClient;
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ import { prismaAdapter } from "better-auth/adapters/prisma";
|
|||||||
import { prisma } from "./prisma";
|
import { prisma } from "./prisma";
|
||||||
|
|
||||||
export const auth = betterAuth({
|
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"],
|
||||||
database: prismaAdapter(prisma, {
|
database: prismaAdapter(prisma, {
|
||||||
provider: "postgresql",
|
provider: "postgresql",
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user