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 { cookies } from "next/headers";
|
||||||
import NextAuth from "next-auth";
|
import NextAuth from "next-auth";
|
||||||
import Credentials from "next-auth/providers/credentials";
|
import Credentials from "next-auth/providers/credentials";
|
||||||
|
import { formatError } from "pretty-print-error";
|
||||||
|
|
||||||
import { db } from "@homarr/db";
|
import { db } from "@homarr/db";
|
||||||
import type { SupportedAuthProvider } from "@homarr/definitions";
|
import type { SupportedAuthProvider } from "@homarr/definitions";
|
||||||
|
import { logger } from "@homarr/log";
|
||||||
|
|
||||||
import { createAdapter } from "./adapter";
|
import { createAdapter } from "./adapter";
|
||||||
import { createSessionCallback } from "./callbacks";
|
import { createSessionCallback } from "./callbacks";
|
||||||
@@ -26,15 +28,16 @@ export const createConfiguration = (
|
|||||||
const adapter = createAdapter(db, provider);
|
const adapter = createAdapter(db, provider);
|
||||||
return NextAuth({
|
return NextAuth({
|
||||||
logger: {
|
logger: {
|
||||||
error: (code, ...message) => {
|
error: (error) => {
|
||||||
// Remove the big error message for failed login attempts
|
// Remove the big error message for failed login attempts
|
||||||
// as it is not useful for the user.
|
// as it is not useful for the user.
|
||||||
if (code.name === "CredentialsSignin") {
|
if (error.name === "CredentialsSignin") {
|
||||||
console.warn("The login attempt of a user was not successful.");
|
logger.warn("The login attempt of a user was not successful.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error(code, ...message);
|
logger.error(formatError(error));
|
||||||
|
logger.error(formatError(error.cause));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
trustHost: true,
|
trustHost: true,
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
"ldapts": "7.3.1",
|
"ldapts": "7.3.1",
|
||||||
"next": "15.1.5",
|
"next": "15.1.5",
|
||||||
"next-auth": "5.0.0-beta.25",
|
"next-auth": "5.0.0-beta.25",
|
||||||
|
"pretty-print-error": "^1.1.2",
|
||||||
"react": "19.0.0",
|
"react": "19.0.0",
|
||||||
"react-dom": "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:
|
next-auth:
|
||||||
specifier: 5.0.0-beta.25
|
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)
|
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:
|
react:
|
||||||
specifier: 19.0.0
|
specifier: 19.0.0
|
||||||
version: 19.0.0
|
version: 19.0.0
|
||||||
|
|||||||
Reference in New Issue
Block a user