{"record":{"id":"d023d22d66359aaa","repo":"jackwener/OpenCLI","slug":"facebook-me-redirected-to-finalurl-logged-o","errorCode":null,"errorMessage":"`Facebook /me redirected to ${finalUrl} — logged out or in checkpoint`","messagePattern":"`Facebook /me redirected to (.+?) — logged out or in checkpoint`","errorType":"error_code","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/facebook/auth.js","lineNumber":21,"sourceCode":"\nasync function hasFacebookCUserCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://www.facebook.com' });\n  return cookies.some(c => c.name === 'c_user' && c.value);\n}\n\nasync function verifyFacebookIdentity(page) {\n  if (!await hasFacebookCUserCookie(page)) {\n    throw new AuthRequiredError('www.facebook.com', 'Facebook c_user cookie missing — anonymous session');\n  }\n  const cookies = await page.getCookies({ url: 'https://www.facebook.com' });\n  const cUser = cookies.find(c => c.name === 'c_user')?.value || '';\n  await page.goto('https://www.facebook.com/me');\n  await page.wait(2);\n  const finalUrl = await page.evaluate(`location.href`);\n  const vanityMatch = String(finalUrl || '').match(/facebook\\.com\\/([^/?#]+)\\/?(?:$|[?#])/);\n  const vanity = vanityMatch?.[1] || '';\n  if (!vanity || vanity === 'login.php' || vanity === 'checkpoint') {\n    throw new AuthRequiredError('www.facebook.com', `Facebook /me redirected to ${finalUrl} — logged out or in checkpoint`);\n  }\n  return {\n    user_id: String(cUser),\n    vanity: String(vanity),\n    profile_url: `https://www.facebook.com/${vanity}/`,\n  };\n}\n\nregisterSiteAuthCommands({\n  site: 'facebook',\n  domain: 'facebook.com',\n  loginUrl: 'https://www.facebook.com/login.php',\n  columns: ['user_id', 'vanity', 'profile_url'],\n  quickCheck: hasFacebookCUserCookie,\n  verify: verifyFacebookIdentity,\n  poll: async (page) => {\n    if (!await hasFacebookCUserCookie(page)) {\n      throw new AuthRequiredError('www.facebook.com', 'Waiting for Facebook c_user cookie');","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/facebook/auth.js#L3-L39","documentation":"After confirming the c_user cookie, verifyFacebookIdentity navigates to facebook.com/me and inspects where the browser actually landed. The final URL's vanity segment must be a real profile path; if the vanity is missing, or the URL is login.php or checkpoint, Facebook bounced the 'logged-in' session out — so it throws AuthRequiredError. This catches sessions where a cookie exists but the login is not actually usable.","triggerScenarios":"Navigating to https://www.facebook.com/me with a c_user cookie present, but location.href after the redirect either has no facebook.com/<vanity> segment, or the vanity equals 'login.php' (logged out) or 'checkpoint' (security checkpoint / 2FA challenge).","commonSituations":"Facebook forced a security checkpoint (new device, suspicious activity, 2FA re-verification); session expired so /me redirects to login.php despite a stale c_user cookie; cookie present but invalid (e.g. copied profile with revoked session).","solutions":["Open the browser interactively and complete the Facebook checkpoint / 2FA challenge, then retry.","Log out and log in again to obtain a fresh valid session (stale cookie present but invalid).","Confirm manually that https://www.facebook.com/me in that browser profile lands on your profile, not login.php or checkpoint.","Use a long-lived, regularly-used browser profile so Facebook's risk system does not flag the session."],"exampleFix":"// before\nconst identity = await verifyFacebookIdentity(page); // throws on checkpoint\n\n// after\ntry {\n  const identity = await verifyFacebookIdentity(page);\n} catch (err) {\n  if (err instanceof AuthRequiredError && err.message.includes('checkpoint')) {\n    await pauseForManualCheckpoint(page); // let the user resolve 2FA in the browser\n  }\n  throw err;\n}","handlingStrategy":"try-catch","validationCode":"const finalUrl = await page.evaluate('location.href');\nconst m = String(finalUrl).match(/facebook\\.com\\/([^/?#]+)/);\nconst vanity = m?.[1] || '';\nconst usable = vanity && vanity !== 'login.php' && vanity !== 'checkpoint';\nif (!usable) await resolveCheckpointInteractively(page);","typeGuard":"function isUsableFacebookUrl(url) {\n  const m = String(url || '').match(/facebook\\.com\\/([^/?#]+)\\/?(?:$|[?#])/);\n  const vanity = m?.[1] || '';\n  return vanity !== '' && vanity !== 'login.php' && vanity !== 'checkpoint';\n}","tryCatchPattern":"try {\n  const identity = await verifyFacebookIdentity(page);\n} catch (err) {\n  if (err instanceof AuthRequiredError && /checkpoint|login\\.php/.test(err.message)) {\n    // pause and let a human resolve the checkpoint in the browser\n  } else {\n    throw err;\n  }\n}","preventionTips":["Verify /me lands on a real profile after login, before batch scraping.","Handle 2FA/checkpoint interactively as soon as Facebook prompts.","Use a warmed-up, regularly-used browser profile to reduce risk flags.","Detect login.php/checkpoint in final URLs of any scrape and abort early."],"tags":["authentication","facebook","redirect","session"],"backgroundTag":"auth-checkpoint-redirect","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}