{"record":{"id":"b5a9aa4fa6bec04f","repo":"RocketChat/Rocket.Chat","slug":"error-no-tokens-for-this-user","errorCode":"error-no-tokens-for-this-user","errorMessage":"There are no tokens for this user","messagePattern":"There are no tokens for this user","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"warning","filePath":"apps/meteor/server/lib/pushConfig.ts","lineNumber":17,"sourceCode":"import type { IUser } from '@rocket.chat/core-typings';\nimport type { ServerMethods } from '@rocket.chat/ddp-client';\nimport { PushToken } from '@rocket.chat/models';\nimport { Meteor } from 'meteor/meteor';\n\nimport { RateLimiterClass as RateLimiter } from './RateLimiter';\nimport { hasPermissionAsync } from './authorization/hasPermission';\nimport { methodDeprecationLogger } from './deprecationWarningLogger';\nimport { i18n } from './i18n';\nimport { settings } from '../settings';\nimport { Push } from './notifications/push';\n\nexport const executePushTest = async (userId: IUser['_id'], username: IUser['username']): Promise<number> => {\n\tconst tokens = await PushToken.countTokensByUserId(userId);\n\n\tif (tokens === 0) {\n\t\tthrow new Meteor.Error('error-no-tokens-for-this-user', 'There are no tokens for this user', {\n\t\t\tmethod: 'push_test',\n\t\t});\n\t}\n\n\tawait Push.send({\n\t\tfrom: 'push',\n\t\ttitle: `@${username}`,\n\t\ttext: i18n.t('This_is_a_push_test_messsage'),\n\t\tsound: 'default',\n\t\tuserId,\n\t});\n\n\treturn tokens;\n};\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/pushConfig.ts#L1-L35","documentation":"executePushTest (behind the push_test method, deprecated in favor of /v1/push/test) counts the user's registered push tokens via PushToken.countTokensByUserId; with zero tokens there is no device to deliver a test to, so it throws Meteor.Error('error-no-tokens-for-this-user', ..., { method: 'push_test' }) before sending anything.","triggerScenarios":"Invoking push_test for a user who never registered a device: no mobile/login client logged in with push configured for that account, tokens wiped (db.rocketchat_push_token empty for the user), or push gateway not set up so tokens were never stored.","commonSituations":"Admins testing push before anyone logged in on the mobile app, testing with a user other than the one holding the device, Push settings (gateway/queue) misconfigured so registration silently failed, or testing right after wiping devices.","solutions":["Log in on a mobile/login client with push enabled as the same user, send any message to trigger registration, then retry push_test","Verify Admin > Push settings (gateway, Push_enable=true) and that the app registered a token (check the push token collection for the user)","Keep in mind push_test is deprecated since 9.0 — prefer the /v1/push/test REST endpoint","If tokens exist but the count is 0 for that user, confirm you're testing with the same userId that owns the device"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// server-side guard before running the test\nimport { PushToken } from '@rocket.chat/models';\n\nconst tokens = await PushToken.countTokensByUserId(userId);\nif (tokens === 0) {\n  return { skipped: true, reason: 'no registered devices — log in on a push-enabled client first' };\n}\nawait executePushTest(userId, username);","typeGuard":null,"tryCatchPattern":"try {\n  await Meteor.callAsync('push_test');\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'error-no-tokens-for-this-user') {\n    // instruct the user to log in on a push-enabled device, then retry\n  } else {\n    throw err;\n  }\n}","preventionTips":["Register at least one device (mobile/login client) before testing push","Verify Push gateway settings and Push_enable=true so token registration works","Prefer the /v1/push/test REST endpoint — push_test is deprecated since 9.0"],"tags":["push","notifications","device-tokens","push-test","deprecated"],"backgroundTag":"push-device-token-missing","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}