fix(auth): user limit resets to 100 on page refresh when policy is unset#3135
fix(auth): user limit resets to 100 on page refresh when policy is unset#3135okxint wants to merge 1 commit into
Conversation
…oded 100 listPolicies omits the user limit policy entirely when no limit has been configured, making userLimitPolicy undefined. The component then fell back to the hardcoded 100 default. Added getDefaultUserLimitPolicy() to match the pattern already used for passwordStrengthPolicy, and added a $effect in the component so value/newLimit stay in sync with the policy prop after invalidation.
Greptile SummaryThis PR fixes how the Auth security page handles the user-limit policy.
Confidence Score: 4/5The user-limit form can discard unsaved edits after project policy refreshes.
src/routes/(console)/project-[region]-[project]/auth/security/updateUsersLimit.svelte Important Files Changed
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
src/routes/(console)/project-[region]-[project]/auth/security/updateUsersLimit.svelte:26-29
**Policy Refresh Discards Edits**
When any security policy form on this page saves, it invalidates the project data and refreshes `data.userLimitPolicy`. This effect then copies the refreshed policy back into `value` and `newLimit`, so a user who is editing the user limit can lose their unsaved radio or number input after an unrelated policy update.
Reviews (1): Last reviewed commit: "fix(auth): initialize user limit from pr..." | Re-trigger Greptile |
| $effect(() => { | ||
| value = policy.total !== 0 ? 'limited' : 'unlimited'; | ||
| newLimit = policy.total !== 0 ? policy.total : 100; | ||
| }); |
There was a problem hiding this comment.
When any security policy form on this page saves, it invalidates the project data and refreshes data.userLimitPolicy. This effect then copies the refreshed policy back into value and newLimit, so a user who is editing the user limit can lose their unsaved radio or number input after an unrelated policy update.
Context Used: AGENTS.md (source)
Knowledge Base Used: Messaging, Storage, and Auth in the project console
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/routes/(console)/project-[region]-[project]/auth/security/updateUsersLimit.svelte
Line: 26-29
Comment:
**Policy Refresh Discards Edits**
When any security policy form on this page saves, it invalidates the project data and refreshes `data.userLimitPolicy`. This effect then copies the refreshed policy back into `value` and `newLimit`, so a user who is editing the user limit can lose their unsaved radio or number input after an unrelated policy update.
**Context Used:** AGENTS.md ([source](https://app.greptile.com/appwrite/github/appwrite/console/-/custom-context?memory=f4227d43-a98a-4882-876a-cad1bc006878))
**Knowledge Base Used:** [Messaging, Storage, and Auth in the project console](https://app.greptile.com/appwrite/-/custom-context/knowledge-base/appwrite/console/-/docs/messaging-storage-authusers.md)
How can I resolve this? If you propose a fix, please make it concise.
After the
listPoliciesmigration, the user limit field in Auth > Security shows 100 on hard refresh regardless of the configured value.Two bugs introduced by that migration:
+page.tshad no fallback default foruserLimitPolicywhen the policy is absent from the API response (i.e., never explicitly configured).passwordStrengthPolicyhad a?? getDefault...()guard;userLimitPolicydid not. This caused the component to receiveundefined, makingpolicy.total !== 0evaluate tofalseand triggering the hardcoded100fallback.updateUsersLimit.svelteinitializedvalue/newLimitfrom the policy prop using$state(). In Svelte 5 runes mode,$state()runs once at mount and does not react to prop changes. Afterinvalidate(Dependencies.PROJECT)re-fetches data and updates the policy prop, the form values stayed stale.Fixes:
getDefaultUserLimitPolicy()returning{ $id: ProjectPolicyId.Userlimit, total: 0 }and applied it as a fallback in+page.ts(matching the existing pattern for other policies).$effectinupdateUsersLimit.svelteto re-derivevalue/newLimitfrom the policy prop on updates.