{"record":{"id":"b30e3e89d768229b","repo":"TryGhost/Ghost","slug":"your-username-is-not-a-valid-tiktok-username","errorCode":null,"errorMessage":"Your Username is not a valid TikTok Username","messagePattern":"Your Username is not a valid TikTok Username","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"apps/admin/src/settings/app/utils/social-urls/tiktok.ts","lineNumber":13,"sourceCode":"import {createPlatformValidator} from './platform-validator';\n\n// TikTok usernames are ASCII-only by platform rule: letters, numbers,\n// underscores and periods, 2–24 characters, no boundary or consecutive periods.\nconst tiktok = createPlatformValidator({\n    domains: ['tiktok.com'],\n    www: true,\n    pathTypes: [\n        {urlPrefix: '@', storagePrefix: '@', rule: {extra: '._', min: 2, max: 24, notAtBoundary: '.', notConsecutive: '.'}}\n    ],\n    errors: {\n        invalidUrl: 'The URL must be in a format like https://www.tiktok.com/@yourUsername',\n        invalidUsername: 'Your Username is not a valid TikTok Username'\n    }\n});\n\nexport const validateTikTokUrl = tiktok.validate;\nexport const tiktokHandleToUrl = tiktok.handleToUrl;\nexport const tiktokUrlToHandle = tiktok.urlToHandle;\n","sourceCodeStart":1,"sourceCodeEnd":20,"githubUrl":"https://github.com/TryGhost/Ghost/blob/47d8b0e2ad2fd4757d3bc45f46c3ac165ff8a1fe/apps/admin/src/settings/app/utils/social-urls/tiktok.ts#L1-L20","documentation":"Thrown by the platform-validator engine for the TikTok definition when the username is invalid, or handleToUrl is called empty. Message declared in tiktok.ts ('Your Username is not a valid TikTok Username'); thrown in platform-validator.ts at: query/fragment in username (line 247), username rule check failure (line 255 — TikTok rule: 2–24 chars, ASCII letters/digits plus ._ , no boundary or consecutive dots), or empty handle in handleToUrl (line 280).","triggerScenarios":"Username fails the TikTok rule: length outside 2–24; contains characters outside [a-zA-Z0-9._]; starts or ends with a dot (notAtBoundary: '.'); contains consecutive dots '..' (notConsecutive: '.'); OR handleToUrl('') with an empty stored handle; OR a URL username segment contains '?' or '#' (query/fragment).","commonSituations":"User typed a 1-character or >24-character handle; handle with leading/trailing dot; handle with consecutive dots; rendering an empty stored handle; user appended a query string to the URL.","solutions":["Use a TikTok handle of 2–24 characters in [a-zA-Z0-9._] with no leading/trailing dot and no consecutive dots.","Guard handleToUrl against empty strings before calling.","Strip query strings and fragments from URLs before validation.","When rendering stored handles, wrap handleToUrl in try-catch and omit the link on failure."],"exampleFix":"// before — throws on empty/corrupt stored handle or out-of-rule handle\nconst url = tiktokHandleToUrl(profile.tiktok);\n\n// after — guard empty, try-catch the rest\nconst handle = profile.tiktok?.trim();\nif (!handle) {\n    return null;\n}\ntry {\n    return tiktokHandleToUrl(handle);\n} catch {\n    return null;\n}","handlingStrategy":"try-catch","validationCode":"// Validate the handle shape before calling handleToUrl\nfunction isValidTikTokHandleShape(h: string): boolean {\n    if (!h || [...h].length < 2 || [...h].length > 24) return false;\n    if (h.startsWith('.') || h.endsWith('.')) return false;\n    if (h.includes('..')) return false;\n    return /^[a-zA-Z0-9._]+$/.test(h);\n}","typeGuard":"null","tryCatchPattern":"const handle = profile.tiktok?.trim();\nif (!handle) return null;\ntry {\n    return tiktokHandleToUrl(handle);\n} catch {\n    return null;\n}","preventionTips":["Use 2–24 characters in [a-zA-Z0-9._] with no boundary or consecutive dots.","Guard handleToUrl against empty strings.","Strip query strings and fragments from URLs before validation.","Wrap handleToUrl in try-catch when rendering from stored data."],"tags":["tiktok","social-urls","validation"],"backgroundTag":null,"analyzedSha":"47d8b0e2ad2fd4757d3bc45f46c3ac165ff8a1fe","analyzedAt":"2026-08-13T01:25:26.651Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}