maltejur / directus-extension-generate-types

Create types for your directus project in your favourite language.
Other
199 stars 24 forks source link

Update admin access check for Directus 11.0.2 compatibility #44

Closed tysonjf closed 1 month ago

tysonjf commented 1 month ago

This pull request updates the preRegisterCheck function in the Generate Types extension to be compatible with both Directus 11 and 11.0.2+. The change addresses the relocation of the admin_access property from the user's role to the user object itself in newer Directus versions.

Changes made:

  1. Updated the type definition for the user parameter in preRegisterCheck to include both possible structures:

    • admin_access directly on the user object
    • admin_access within the role object
  2. Modified the preRegisterCheck function to check for admin_access in both locations using the nullish coalescing operator (??).

  3. Added a fallback to false if admin_access is not found in either location.

This change ensures backwards compatibility with older Directus versions while supporting the new structure in Directus 11.0.2 and later.

Testing:

Please review and test this change to ensure it meets the requirements for both new and existing Directus installations.

maltejur commented 1 month ago

Thanks, I merged a fix for this in https://github.com/maltejur/directus-extension-generate-types/pull/41 just now