chore: make error messages for auth errors more detailed (#2041)
This commit is contained in:
@@ -2,9 +2,11 @@ import type { ReadonlyHeaders } from "next/dist/server/web/spec-extension/adapte
|
||||
import { cookies } from "next/headers";
|
||||
import NextAuth from "next-auth";
|
||||
import Credentials from "next-auth/providers/credentials";
|
||||
import { formatError } from "pretty-print-error";
|
||||
|
||||
import { db } from "@homarr/db";
|
||||
import type { SupportedAuthProvider } from "@homarr/definitions";
|
||||
import { logger } from "@homarr/log";
|
||||
|
||||
import { createAdapter } from "./adapter";
|
||||
import { createSessionCallback } from "./callbacks";
|
||||
@@ -26,15 +28,16 @@ export const createConfiguration = (
|
||||
const adapter = createAdapter(db, provider);
|
||||
return NextAuth({
|
||||
logger: {
|
||||
error: (code, ...message) => {
|
||||
error: (error) => {
|
||||
// Remove the big error message for failed login attempts
|
||||
// as it is not useful for the user.
|
||||
if (code.name === "CredentialsSignin") {
|
||||
console.warn("The login attempt of a user was not successful.");
|
||||
if (error.name === "CredentialsSignin") {
|
||||
logger.warn("The login attempt of a user was not successful.");
|
||||
return;
|
||||
}
|
||||
|
||||
console.error(code, ...message);
|
||||
logger.error(formatError(error));
|
||||
logger.error(formatError(error.cause));
|
||||
},
|
||||
},
|
||||
trustHost: true,
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
"ldapts": "7.3.1",
|
||||
"next": "15.1.5",
|
||||
"next-auth": "5.0.0-beta.25",
|
||||
"pretty-print-error": "^1.1.2",
|
||||
"react": "19.0.0",
|
||||
"react-dom": "19.0.0"
|
||||
},
|
||||
|
||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -642,6 +642,9 @@ importers:
|
||||
next-auth:
|
||||
specifier: 5.0.0-beta.25
|
||||
version: 5.0.0-beta.25(next@15.1.5(@babel/core@7.26.0)(@playwright/test@1.49.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(sass@1.83.4))(react@19.0.0)
|
||||
pretty-print-error:
|
||||
specifier: ^1.1.2
|
||||
version: 1.1.2(patch_hash=4arrfgbz7em6s4gqywse7esg4u)
|
||||
react:
|
||||
specifier: 19.0.0
|
||||
version: 19.0.0
|
||||
|
||||
Reference in New Issue
Block a user