mirror of
https://github.com/gethomepage/homepage.git
synced 2026-08-31 01:15:53 -07:00
Tweak: improve nextauth error logging for easier debugging (#7070)
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
This commit is contained in:
@@ -73,6 +73,7 @@ describe("pages/api/auth/[...nextauth]", () => {
|
||||
it("routes sanitized NextAuth logs through the Homepage logger", async () => {
|
||||
const mod = await import("pages/api/auth/[...nextauth]");
|
||||
const sensitiveMetadata = {
|
||||
error: Object.assign(new Error("State cookie was missing."), { access_token: "sensitive-access-token" }),
|
||||
clientSecret: "sensitive-client-secret",
|
||||
access_token: "sensitive-access-token",
|
||||
id_token: "sensitive-id-token",
|
||||
@@ -82,7 +83,7 @@ describe("pages/api/auth/[...nextauth]", () => {
|
||||
mod.authOptions.logger.warn("NEXTAUTH_URL", sensitiveMetadata);
|
||||
mod.authOptions.logger.debug("OAUTH_CALLBACK_RESPONSE", sensitiveMetadata);
|
||||
|
||||
expect(errorMock).toHaveBeenCalledWith("%s", "OAUTH_CALLBACK_ERROR");
|
||||
expect(errorMock).toHaveBeenCalledWith("%s: %s", "OAUTH_CALLBACK_ERROR", "State cookie was missing.");
|
||||
expect(warnMock).toHaveBeenCalledWith("%s", "NEXTAUTH_URL");
|
||||
expect(debugMock).toHaveBeenCalledWith("%s", "OAUTH_CALLBACK_RESPONSE");
|
||||
expect(JSON.stringify([...errorMock.mock.calls, ...warnMock.mock.calls, ...debugMock.mock.calls])).not.toContain(
|
||||
|
||||
@@ -71,6 +71,16 @@ function logFailedPasswordSignIn() {
|
||||
createLogger("nextauth").warn("Failed password sign-in attempt");
|
||||
}
|
||||
|
||||
function logNextAuthError(code, metadata) {
|
||||
const error = metadata instanceof Error ? metadata : metadata?.error;
|
||||
|
||||
if (error?.message) {
|
||||
createLogger("nextauth").error("%s: %s", code, error.message);
|
||||
} else {
|
||||
createLogger("nextauth").error("%s", code);
|
||||
}
|
||||
}
|
||||
|
||||
let providers = [];
|
||||
if (authEnabled) {
|
||||
if (hasOidcConfig) {
|
||||
@@ -140,7 +150,7 @@ export const authOptions = {
|
||||
signIn: "/auth/signin",
|
||||
},
|
||||
logger: {
|
||||
error: (code) => createLogger("nextauth").error("%s", code),
|
||||
error: logNextAuthError,
|
||||
warn: (code) => createLogger("nextauth").warn("%s", code),
|
||||
debug: (code) => createLogger("nextauth").debug("%s", code),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user