twentyhq/twenty · critical · Error
${currentUserResult.error.message}
Error message
${currentUserResult.error.message} What it means
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.
Source
Thrown at packages/twenty-front/src/modules/users/hooks/useLoadCurrentUser.ts:55
const setCurrentWorkspace = useSetAtomState(currentWorkspaceState);
const { initializeFormatPreferences } = useInitializeFormatPreferences();
const setWorkspaceAuthBypassProviders = useSetAtomState(
workspaceAuthBypassProvidersState,
);
const authProviders = useAtomStateValue(authProvidersState);
const { isOnAWorkspace } = useIsCurrentLocationOnAWorkspace();
const client = useApolloClient();
const loadCurrentUser = useCallback(async () => {
const currentUserResult = await client.query({
query: GetCurrentUserDocument,
fetchPolicy: 'network-only',
});
if (isDefined(currentUserResult.error)) {
throw new Error(currentUserResult.error.message);
}
const user = currentUserResult.data?.currentUser;
if (!isDefined(user)) {
throw new Error('No current user result');
}
let workspaceMember = null;
setCurrentUser(user);
if (isDefined(user.workspaceMembers)) {
setCurrentWorkspaceMembers(user.workspaceMembers);
}
if (isDefined(user.availableWorkspaces)) {
setAvailableWorkspaces(user.availableWorkspaces);View on GitHub (pinned to 1f5dd2bbd2)
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.
Example fix
// before: if (isDefined(currentUserResult.error)) { throw new Error(currentUserResult.error.message); }
// after: if (isDefined(currentUserResult.error)) {
// if (currentUserResult.error.networkError) redirect('/sign-in');
// throw new Error(currentUserResult.error.message);
// } Defensive patterns
Strategy: try-catch
Validate before calling
const queryCurrentUserSafe = async (client: ApolloClient<unknown>) => {
const res = await client.query({ query: GetCurrentUserDocument, fetchPolicy: 'network-only' });
if (isDefined(res.error)) throw new Error(res.error.message);
return res.data?.currentUser;
}; Type guard
const isApolloNetworkError = (e: unknown): boolean => e instanceof Error && /Network error|Failed to fetch|load failed/i.test(e.message); const isAuthError = (e: unknown): boolean => e instanceof Error && /401|403|unauthorized|forbidden/i.test(e.message);
Try / catch
try {
await loadCurrentUser();
} catch (e) {
const msg = (e as Error).message;
if (isAuthError(e) || /network/i.test(msg)) {
redirectToSignIn();
} else {
showError(msg);
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Session expired while the app was idle. Backend down or restarting. Auth cookie/token cleared. Workspace subdomain/DNS misconfigured. CORS preflight rejected.
Related errors
- No getAuthTokensFromSSOExchangeToken result
- No response from server
- ${res.statusText}: ${await res.text()}
- ${response.statusText}: ${response.rawBody}
- Invalid JSON response
AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12).
Data as JSON: /api/errors/2bf6361261abbcd8.
Report an issue: GitHub.