{"record":{"id":"b517e521bda2a88c","repo":"jackwener/OpenCLI","slug":"authrequirederror-mubu-domain-auth-hint","errorCode":null,"errorMessage":"AuthRequiredError(MUBU_DOMAIN, AUTH_HINT)","messagePattern":"AuthRequiredError\\(MUBU_DOMAIN, AUTH_HINT\\)","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/mubu/utils.js","lineNumber":42,"sourceCode":"      if (!token) return { ok: false, status: 0, data: null, error: 'no token' };\n      return await new Promise((resolve) => {\n        const xhr = new XMLHttpRequest();\n        xhr.open('POST', ${JSON.stringify(url)}, true);\n        xhr.setRequestHeader('Content-Type', 'application/json');\n        xhr.setRequestHeader('Jwt-Token', token);\n        xhr.onload = () => {\n          let data = null;\n          try { data = JSON.parse(xhr.responseText); } catch {}\n          resolve({ ok: xhr.status >= 200 && xhr.status < 300, status: xhr.status, data });\n        };\n        xhr.onerror = () => resolve({ ok: false, status: 0, data: null, error: 'network error' });\n        xhr.send(${JSON.stringify(JSON.stringify(body))});\n      });\n    })()\n  `);\n\n  if (!result || result.error === 'no token') {\n    throw new AuthRequiredError(MUBU_DOMAIN, AUTH_HINT);\n  }\n  if (!result.ok || !result.data) {\n    throw new CommandExecutionError(`mubu: ${path}: HTTP ${result.status} ${result.error ?? ''}`);\n  }\n\n  const { data } = result;\n  if (data.code !== 0) {\n    if (isAuthFailure(data.code, data.message)) {\n      throw new AuthRequiredError(MUBU_DOMAIN, AUTH_HINT);\n    }\n    throw new CommandExecutionError(`mubu: ${path}: code=${data.code} ${data.message ?? ''}`);\n  }\n\n  return data.data;\n}\n\nexport function formatDate(ts) {\n  if (!ts) return '';","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/mubu/utils.js#L24-L60","documentation":"mubuPost runs an XHR inside the browser page and reads the Jwt-Token from localStorage. When the token is missing (result.error === 'no token'), it throws AuthRequiredError telling you to log in at mubu.com in that browser session.","triggerScenarios":"Calling any mubu API command in a browser profile where the user is not logged into mubu.com, after localStorage was cleared, or in a fresh automation profile with no cookies/localStorage.","commonSituations":"Headless browser contexts, incognito profiles, sessions purged from localStorage, or pointing the CLI at the wrong user-data-dir.","solutions":["Open mubu.com in the controlled browser and log in, then retry.","Point the CLI at the browser profile that already has the session (correct user-data-dir).","Catch AuthRequiredError and surface the login hint to the user instead of retrying."],"exampleFix":"// before\nconst data = await mubuPost(page, '/doc/list', body); // throws if not logged in\n// after\ntry {\n  const data = await mubuPost(page, '/doc/list', body);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await page.goto('https://mubu.com'); // prompt user to log in\n    return;\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"const hasToken = await page.evaluate(() => !!localStorage.getItem('Jwt-Token'));\nif (!hasToken) throw new Error('Not logged into mubu.com in this browser profile');","typeGuard":"const isLoggedIn = async (page) => page.evaluate(() => !!localStorage.getItem('Jwt-Token'));","tryCatchPattern":"try {\n  const data = await mubuPost(page, path, body);\n} catch (e) {\n  if (e.name === 'AuthRequiredError') {\n    await page.goto('https://mubu.com'); // let the user log in\n  } else throw e;\n}","preventionTips":["Check for Jwt-Token in localStorage before issuing API calls.","Use a persistent browser profile that stays logged in.","Catch AuthRequiredError explicitly — never retry it blindly."],"tags":["auth","browser-session","token-missing"],"backgroundTag":"auth-required-login-expired","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}