{"record":{"id":"cc323cf4877f94a6","repo":"amir20/dozzle","slug":"err-error-cc323c","errorCode":null,"errorMessage":"err.Error()","messagePattern":"err\\.Error\\(\\)","errorType":"http","errorClass":null,"httpStatus":401,"severity":"error","filePath":"internal/web/auth.go","lineNumber":35,"sourceCode":"\t\tif h.config.Authorization.TTL > 0 {\n\t\t\texpires = time.Now().Add(h.config.Authorization.TTL)\n\t\t}\n\n\t\thttp.SetCookie(w, &http.Cookie{\n\t\t\tName:     \"jwt\",\n\t\t\tValue:    token,\n\t\t\tHttpOnly: true,\n\t\t\tPath:     \"/\",\n\t\t\tSameSite: http.SameSiteLaxMode,\n\t\t\tSecure:   isHTTPS(r),\n\t\t\tExpires:  expires,\n\t\t})\n\t\tlog.Info().Str(\"user\", user).Msg(\"Token created\")\n\t\tw.WriteHeader(http.StatusOK)\n\t\tw.Write([]byte(http.StatusText(http.StatusOK)))\n\t} else {\n\t\tlog.Error().Err(err).Msg(\"Failed to create token\")\n\t\thttp.Error(w, err.Error(), http.StatusUnauthorized)\n\t}\n}\n\nfunc (h *handler) deleteToken(w http.ResponseWriter, r *http.Request) {\n\thttp.SetCookie(w, &http.Cookie{\n\t\tName:     \"jwt\",\n\t\tValue:    \"\",\n\t\tHttpOnly: true,\n\t\tPath:     \"/\",\n\t\tSameSite: http.SameSiteLaxMode,\n\t\tSecure:   isHTTPS(r),\n\t\tExpires:  time.Unix(0, 0),\n\t})\n\tw.WriteHeader(http.StatusOK)\n\tw.Write([]byte(http.StatusText(http.StatusOK)))\n}\n\n// isHTTPS reports whether the original client request used HTTPS, accounting","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/amir20/dozzle/blob/d9463cbe21874e44ab79db6fa63e746ca7d22928/internal/web/auth.go#L17-L53","documentation":"createToken authenticates a user (typically LDAP/simple backend validation) and issues a JWT; when token creation fails (invalid credentials or internal signing error), the raw error is returned with 401 Unauthorized.","triggerScenarios":"POST to the token endpoint with wrong username/password, a user that the auth backend cannot validate, or an internal failure generating the JWT (bad secret).","commonSituations":"Typos in users.yml credentials; user forgetting password after config change; LDAP unavailable; shared secret misconfigured so signing fails.","solutions":["Verify the username/password (check users.yml or the auth provider)","Check Dozzle debug logs for 'Failed to create token' with the underlying error","If signing errors: verify the JWT secret configuration and restart Dozzle","Re-test login after fixing credentials; clear stale cookies first"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!username || !password) throw new Error('credentials required before requesting a token');","typeGuard":null,"tryCatchPattern":"const res = await fetch('/api/token', {method: 'POST', body: creds});\nif (res.status === 401) {\n  const msg = await res.text();\n  throw new Error(`login failed: ${msg}`); // prompt user to re-enter credentials\n}","preventionTips":["Validate credentials against users.yml / auth provider before automation","Clear stale jwt cookies before re-login attempts","Monitor 'Failed to create token' debug logs when changing auth configuration"],"tags":["auth","jwt","login","unauthorized"],"backgroundTag":"jwt-token-expired","analyzedSha":"d9463cbe21874e44ab79db6fa63e746ca7d22928","analyzedAt":"2026-09-07T10:08:55.855Z","contentChangedAt":"2026-09-07T10:08:55.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}