postiz-app
postiz-app copied to clipboard
Use string compairson for the env var DISABLE_REGISTRATION so that it works properly
What kind of change does this PR introduce?
Bug fix, #730
Why was this change needed?
I ran into an issue where DISABLE_REGISTRATION was set to false, but it still acted as though it was set to true
Other information:
I didn't talk to anybody, I just saw the issue, figured out why it happened, and wanted to fix it
Checklist:
Put a "X" in the boxes below to indicate you have followed the checklist;
- [X] I have read the CONTRIBUTING guide.
- [X] I checked that there were not similar issues or PRs already open for this.
- [X] This PR fixes just ONE issue (do not include multiple issues or types of change in the same PR) For example, don't try and fix a UI issue and include new dependencies in the same PR.
Summary by CodeRabbit
- Bug Fixes
- Improved handling of the registration disable setting to ensure registration is only disabled when the environment variable is set to "true". This prevents unintended blocking of registration due to loosely set environment values.
@dattas is attempting to deploy a commit to the Listinai Team on Vercel.
A member of the Team first needs to authorize it.
Walkthrough
The changes update the logic for checking the DISABLE_REGISTRATION environment variable in both backend and frontend authentication code. The check now explicitly compares the variable to the string "true" instead of relying on truthy or falsy evaluation, ensuring registration is only disabled when the value is exactly "true".
Changes
| Files | Change Summary |
|---|---|
| apps/backend/src/services/auth/auth.service.ts | Updated canRegister logic to use explicit string comparison (!== "true") for DISABLE_REGISTRATION. |
| apps/frontend/src/app/(app)/auth/page.tsx | Changed conditional to check if DISABLE_REGISTRATION === "true" instead of a general truthy check. |
Possibly related PRs
- gitroomhq/postiz-app#569: Introduced the
canRegistermethod and integrated it into backend and frontend registration logic; the current PR directly modifies the logic added in this PR.
Poem
A toggle for sign-ups, so clear and so true,
Now checks for a string, not just any old clue.
"DISABLE_REGISTRATION" must say "true"—
For the gate to be closed, and the sign-ups be few.
🐇✨
[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
🔧 ESLint
If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
apps/backend/src/services/auth/auth.service.ts
Oops! Something went wrong! :(
ESLint: 8.57.0
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@eslint/eslintrc' imported from /eslint.config.mjs at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9) at packageResolve (node:internal/modules/esm/resolve:767:81) at moduleResolve (node:internal/modules/esm/resolve:853:18) at defaultResolve (node:internal/modules/esm/resolve:983:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12) at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25) at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38) at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38) at #link (node:internal/modules/esm/module_job:201:49)
apps/frontend/src/app/(app)/auth/page.tsx
Oops! Something went wrong! :(
ESLint: 8.57.0
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@eslint/eslintrc' imported from /eslint.config.mjs at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9) at packageResolve (node:internal/modules/esm/resolve:767:81) at moduleResolve (node:internal/modules/esm/resolve:853:18) at defaultResolve (node:internal/modules/esm/resolve:983:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12) at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25) at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38) at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38) at #link (node:internal/modules/esm/module_job:201:49)
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between ad21ea0dd3e752a4c0b54f8058c2d02c2e494415 and 24412c04997a0f9e91e5b170e642dce742352a1f.
📒 Files selected for processing (2)
apps/backend/src/services/auth/auth.service.ts(1 hunks)apps/frontend/src/app/(app)/auth/page.tsx(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build-and-publish
🔇 Additional comments (2)
apps/frontend/src/app/(app)/auth/page.tsx (1)
15-15: Excellent fix for the environment variable comparison bug.The change from
if (process.env.DISABLE_REGISTRATION)toif (process.env.DISABLE_REGISTRATION === "true")correctly addresses the issue where settingDISABLE_REGISTRATION=falsewould still disable registration. Environment variables are strings, so the previous truthy check would treat "false" as truthy.apps/backend/src/services/auth/auth.service.ts (1)
24-24: Perfect alignment with frontend logic.The change from
!process.env.DISABLE_REGISTRATIONtoprocess.env.DISABLE_REGISTRATION !== "true"creates consistent behavior with the frontend fix. Registration is now only disabled when the environment variable is exactly "true", resolving the bug where "false" would incorrectly disable registration.
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Explain this complex logic.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai explain this code block.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and explain its main purpose.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
I don't see what is the problem with the current implementation. if DISABLE_REGISTRATION doesn't exist than it's false. if DISABLE_REGISTRATION is either "true" or true, then it's true. This implementation can actually create more problems.
That is the problem, if it's "exists" then it's "true", even if it's set to "false", so this causes a lot of problems
What happens on some computer where false is translated as "false". It's better just to remove the variable
Typically when your application uses a lot of env vars, you'd want all environment variables to be parsed by a configuration class. Then you'd call to that class to ensure consistent processing of the variable instead of having to parse each one each time you want to check (and you can handle logic in that single place instead of having to repeat the logic in the multiple places). We can certainly create a class like this so you are not having to pull raw env vars anywhere you want to use them. I simply wrote something minimal that will fix an existing open issue and something that tripped me up due to the behavior being inconsistent with the application's documentation and with most software's established standards. If I used something like nodejs workers, the existing implementation where you want the env variable to exist or not would not work properly as you can use the nodejs workers to pass non-string environment variables. I believe it is better to have a consistent and established behavior and documentation. If someone runs Postiz and manages to pass a boolean to the application instead of a string (like using a nodejs worker), they're outside normal operations and I'd argue supported setup of the application. Since the docker is the recommended setup, it isn't possible (that I'm aware of) for a user to get a boolean to not be coerced into a string past docker/docker compose and past pm2 (it'd just become a string) so trying to worry about unsupported setups isn't something I'd personally spend a lot of time worrying about people encountering.
With that said, it is currently very confusing not only in the documentation of Postiz ( https://docs.postiz.com/configuration/reference ) indicating an example is true (when right now the behavior is it doesn't matter, only if it is set or not), and the env file indicating and defaulting to false which actually is still disabling the registration. This is confusing because with it set to false, you'd expect it not to be disabled, however if it is set at all, it will be disabled. This behavior isn't documented anywhere I could find, is documented to be like a standard environment variable (set the value and get the behavior), and the env var existing is the only thing that is checked (the value is not) isn't something I've ever encountered professionally or with my large homelab setup.
I implemented this function using javascript's strict equality operator, the === or !== to ensure that it will not translate truthy like a == may explicitly to avoid confusion like corrupted environments causing problems. If you want to handle edge cases like you're describing I can change it to use something like yn ( https://www.npmjs.com/package/yn ) which is quite established package to ensure that a variety of values is checked to allow the handling of things that can be coerced safely into a boolean. I just assumed that an extra dependency to make the behavior match the documentation and I'd argue most people's expectations was undesired. Let me know if you'd like me to update the PR with something like yn and I'd happily do so!
This PR is stale because it has been open for 90 days with no activity.
This PR was closed because it has been inactive for 7 days since being marked as stale.