Title: bug: invalid replacement userId tears down current SDK user state · Issue #8288 · formbricks/formbricks · GitHub
Open Graph Title: bug: invalid replacement userId tears down current SDK user state · Issue #8288 · formbricks/formbricks
X Title: bug: invalid replacement userId tears down current SDK user state · Issue #8288 · formbricks/formbricks
Description: Issue Summary bug: invalid replacement userId tears down current SDK user state ## Issue `setUserId` currently tears down the existing SDK user state before validating the replacement `userId` length. This means an invalid oversized repl...
Open Graph Description: Issue Summary bug: invalid replacement userId tears down current SDK user state ## Issue `setUserId` currently tears down the existing SDK user state before validating the replacement `userId` leng...
X Description: Issue Summary bug: invalid replacement userId tears down current SDK user state ## Issue `setUserId` currently tears down the existing SDK user state before validating the replacement `userId` leng...
Opengraph URL: https://github.com/formbricks/formbricks/issues/8288
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"bug: invalid replacement userId tears down current SDK user state","articleBody":"### Issue Summary\n\n\n```text\nbug: invalid replacement userId tears down current SDK user state\n```\n\n\n```md\n## Issue\n\n`setUserId` currently tears down the existing SDK user state before validating the replacement `userId` length.\n\nThis means an invalid oversized replacement `userId` can clear the current valid user even though the new value is rejected.\n\n## Reproduction\n\nCurrent order in `packages/js-core/src/lib/user/user.ts`:\n\n```ts\nif (currentUserId) {\n tearDown();\n}\n\nconst MAX_USER_ID_LENGTH = 255;\nif (userId.length \u003e MAX_USER_ID_LENGTH) {\n return okVoid();\n}\n```\n\nExample flow:\n\n```ts\nawait formbricks.setUserId(\"existing-user\");\nawait formbricks.setUserId(\"a\".repeat(256));\n```\n\n## Current behavior\n\n- Existing user state is torn down.\n- The oversized replacement `userId` is rejected.\n- No new user is set.\n- The SDK loses the previously valid user state.\n\n## Expected behavior\n\nThe replacement `userId` should be validated before tearing down the current user.\n\nIf the new `userId` is invalid, the SDK should reject it without clearing the existing valid user state.\n\n## Minimal fix\n\nMove the max-length validation before the `tearDown()` call.\n\nI verified this with a focused regression test:\n\n```bash\nvitest run src/lib/user/tests/user.test.ts\n```\n\nResult after fix:\n\n```text\n1 file passed, 7 tests passed\n```\n\nFocused ESLint also passes for:\n\n```bash\neslint src/lib/user/user.ts src/lib/user/tests/user.test.ts\n```\n\nBranch:\nhttps://github.com/bharathkumar39293/formbricks/tree/fix/sdk-setuserid-validate-before-teardown\n\nSince PR creation is restricted, I’m happy to open a PR if access is enabled, or a maintainer can cherry-pick the commit if preferred.\n```\n\n### Expected Behavior\n\n_No response_\n\n### Other information (incl. screenshots, Formbricks version, steps to reproduce,...)\n\n_No response_\n\n### Your Environment\n\nNone","author":{"url":"https://github.com/bharathkumar39293","@type":"Person","name":"bharathkumar39293"},"datePublished":"2026-06-16T05:43:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/8288/formbricks/issues/8288"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6b966033-0c75-b64f-b258-8cec77e4c60e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AD48:EE93:772A8C:AB6AEE:6A4BB293 |
| html-safe-nonce | 42294cf33156e0a97153938b8f730010b1c69210babcea3e261c0bd105c5f469 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDQ4OkVFOTM6NzcyQThDOkFCNkFFRTo2QTRCQjI5MyIsInZpc2l0b3JfaWQiOiI3OTA3NDE1NjMyNzY0NDQ5NDI3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7d303c3dc029b186cb4a39d28ecab8f7434b2abc517a4c6351841c5b2b474bac |
| hovercard-subject-tag | issue:4671414699 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/formbricks/formbricks/8288/issue_layout |
| twitter:image | https://opengraph.githubassets.com/177285f48c620b2ce0db78272935d6e9692f4cbd29b3dd6d809c358cbe8b4f46/formbricks/formbricks/issues/8288 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/177285f48c620b2ce0db78272935d6e9692f4cbd29b3dd6d809c358cbe8b4f46/formbricks/formbricks/issues/8288 |
| og:image:alt | Issue Summary bug: invalid replacement userId tears down current SDK user state ## Issue `setUserId` currently tears down the existing SDK user state before validating the replacement `userId` leng... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bharathkumar39293 |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae1c14875555a1dd92bdef45baa6dd9aa796df891e4e471989f7117fe3139fc1 |
| turbo-cache-control | no-preview |
| go-import | github.com/formbricks/formbricks git https://github.com/formbricks/formbricks.git |
| octolytics-dimension-user_id | 105877416 |
| octolytics-dimension-user_login | formbricks |
| octolytics-dimension-repository_id | 500289888 |
| octolytics-dimension-repository_nwo | formbricks/formbricks |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 500289888 |
| octolytics-dimension-repository_network_root_nwo | formbricks/formbricks |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 68fba4ebcf15cde644b66de9a06e0a8582279435 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width