{"record":{"id":"2bf6361261abbcd8","repo":"twentyhq/twenty","slug":"currentuserresult-error-message","errorCode":null,"errorMessage":"${currentUserResult.error.message}","messagePattern":"\\$\\{currentUserResult\\.error\\.message\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/twenty-front/src/modules/users/hooks/useLoadCurrentUser.ts","lineNumber":55,"sourceCode":"  const setCurrentWorkspace = useSetAtomState(currentWorkspaceState);\n  const { initializeFormatPreferences } = useInitializeFormatPreferences();\n  const setWorkspaceAuthBypassProviders = useSetAtomState(\n    workspaceAuthBypassProvidersState,\n  );\n  const authProviders = useAtomStateValue(authProvidersState);\n\n  const { isOnAWorkspace } = useIsCurrentLocationOnAWorkspace();\n\n  const client = useApolloClient();\n\n  const loadCurrentUser = useCallback(async () => {\n    const currentUserResult = await client.query({\n      query: GetCurrentUserDocument,\n      fetchPolicy: 'network-only',\n    });\n\n    if (isDefined(currentUserResult.error)) {\n      throw new Error(currentUserResult.error.message);\n    }\n\n    const user = currentUserResult.data?.currentUser;\n\n    if (!isDefined(user)) {\n      throw new Error('No current user result');\n    }\n\n    let workspaceMember = null;\n\n    setCurrentUser(user);\n\n    if (isDefined(user.workspaceMembers)) {\n      setCurrentWorkspaceMembers(user.workspaceMembers);\n    }\n\n    if (isDefined(user.availableWorkspaces)) {\n      setAvailableWorkspaces(user.availableWorkspaces);","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-front/src/modules/users/hooks/useLoadCurrentUser.ts#L37-L73","documentation":"Thrown in useLoadCurrentUser when the Apollo GetCurrentUser query returns with a populated `error` field. The thrown Error message is Apollo's error.message verbatim (network failure message, or the first GraphQL error). This blocks the entire post-login bootstrap since user/workspace state cannot be populated.","triggerScenarios":"Network failure reaching the backend. 401/403 from an expired or invalid session token. GraphQL errors array populated by the server (resolver threw). CORS/DNS issues hitting the API host.","commonSituations":"Session expired while the app was idle. Backend down or restarting. Auth cookie/token cleared. Workspace subdomain/DNS misconfigured. CORS preflight rejected.","solutions":["Read the thrown message to classify: 'Network error' vs a GraphQL error string vs 'Unauthorized'.","For 401/403, redirect to sign-in and refresh the session token.","For network errors, verify the API base URL and backend availability, then retry the query."],"exampleFix":"// before: if (isDefined(currentUserResult.error)) { throw new Error(currentUserResult.error.message); }\n// after:  if (isDefined(currentUserResult.error)) {\n//           if (currentUserResult.error.networkError) redirect('/sign-in');\n//           throw new Error(currentUserResult.error.message);\n//         }","handlingStrategy":"try-catch","validationCode":"const queryCurrentUserSafe = async (client: ApolloClient<unknown>) => {\n  const res = await client.query({ query: GetCurrentUserDocument, fetchPolicy: 'network-only' });\n  if (isDefined(res.error)) throw new Error(res.error.message);\n  return res.data?.currentUser;\n};","typeGuard":"const isApolloNetworkError = (e: unknown): boolean =>\n  e instanceof Error && /Network error|Failed to fetch|load failed/i.test(e.message);\nconst isAuthError = (e: unknown): boolean =>\n  e instanceof Error && /401|403|unauthorized|forbidden/i.test(e.message);","tryCatchPattern":"try {\n  await loadCurrentUser();\n} catch (e) {\n  const msg = (e as Error).message;\n  if (isAuthError(e) || /network/i.test(msg)) {\n    redirectToSignIn();\n  } else {\n    showError(msg);\n  }\n}","preventionTips":["Refresh the session token before bootstrapping if it is near expiry.","Handle network-error vs auth-error branches distinctly in the caller.","On 401/403, clear stale auth state and send the user to sign-in rather than crashing the bootstrap."],"tags":["auth","graphql","apollo","network","bootstrap"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}