{"record":{"id":"61f43d2940dd4a9c","repo":"RocketChat/Rocket.Chat","slug":"not-logged-in","errorCode":null,"errorMessage":"Not logged in","messagePattern":"Not logged in","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/client/components/message/content/reactions/useToggleReactionMutation.ts","lineNumber":20,"sourceCode":"import { useEndpoint, useUserId } from '@rocket.chat/ui-contexts';\nimport type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\ntype UseToggleReactionMutationVariables = {\n\tmid: IMessage['_id'];\n\treaction: string;\n};\n\nexport const useToggleReactionMutation = (\n\toptions?: Omit<UseMutationOptions<void, Error, UseToggleReactionMutationVariables>, 'mutationFn'>,\n): UseMutationResult<void, Error, UseToggleReactionMutationVariables> => {\n\tconst uid = useUserId();\n\tconst reactToMessage = useEndpoint('POST', '/v1/chat.react');\n\n\treturn useMutation({\n\t\tmutationFn: async ({ mid, reaction }) => {\n\t\t\tif (!uid) {\n\t\t\t\tthrow new Error('Not logged in');\n\t\t\t}\n\n\t\t\tawait reactToMessage({ messageId: mid, reaction });\n\t\t},\n\n\t\t...options,\n\t});\n};\n","sourceCodeStart":2,"sourceCodeEnd":29,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/client/components/message/content/reactions/useToggleReactionMutation.ts#L2-L29","documentation":"Thrown by useToggleReactionMutation when the current user id (useUserId()) is falsy at the moment the mutation function runs. The guard exists because chat.react requires an authenticated session; reacting before login would otherwise send an unauthenticated POST that fails opaquely on the server. Throwing early gives a clear client-side cause.","triggerScenarios":"Calling mutate({ mid, reaction }) when the user is logged out, the account is in a logging-out transition, the session token was cleared, or useUserId returned undefined because the UserContext provider has no loaded user. Also reachable if the component rendering the reaction button outlives the session teardown.","commonSituations":"The user clicked a reaction button in the instant their session expired; a background tab resumed after the token expired; an automated/E2E test that did not establish a logged-in session before interacting; a race where the reaction mutation fires during logout.","solutions":["Ensure the component using this hook is only rendered/interactive when a valid user session exists — gate the reaction UI behind a logged-in check.","If the error appears unexpectedly, check that the login flow completed and Meteor.userId() is set before enabling reactions.","In tests, seed the logged-in user (Meteor.userId) before triggering the mutation.","Handle the error in the mutation's onError to silently re-prompt login instead of showing a raw toast."],"exampleFix":"// before: button always enabled\n<ReactionButton onClick={() => toggle.mutate({ mid, reaction })} />\n\n// after: disable when not logged in\nconst uid = useUserId();\n<ReactionButton disabled={!uid} onClick={() => toggle.mutate({ mid, reaction })} />","handlingStrategy":"validation","validationCode":"const uid = useUserId();\nif (!uid) { throw new Error('Login required'); }\n// or gate the UI: <button disabled={!uid} />","typeGuard":"function isLoggedIn(uid: string | null | undefined): uid is string {\n  return typeof uid === 'string' && uid.length > 0;\n}","tryCatchPattern":"try {\n  await toggle.mutateAsync({ mid, reaction });\n} catch (e) {\n  if ((e as Error).message === 'Not logged in') {\n    redirectToLogin();\n  }\n}","preventionTips":["Disable reaction controls when useUserId() is falsy.","Do not render interactive message actions during logout transitions.","Seed a logged-in user in E2E tests before triggering reactions."],"tags":["reaction","auth","mutation","session"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}