Skip to content

Fix: prevent null account_id when creating identity from Accounts UI#6579

Open
HussainAther wants to merge 2 commits into
Hubs-Foundation:masterfrom
HussainAther:fix/identity-create-null-account-id
Open

Fix: prevent null account_id when creating identity from Accounts UI#6579
HussainAther wants to merge 2 commits into
Hubs-Foundation:masterfrom
HussainAther:fix/identity-create-null-account-id

Conversation

@HussainAther

@HussainAther HussainAther commented May 2, 2026

Copy link
Copy Markdown

What?

Fixes an issue where the "Create Identity" link in the Accounts admin UI could generate a URL with a missing or invalid account_id.

Adds a guard in IdentityCreateLink to ensure that record.id exists before constructing the link. If the ID is missing, the link is rendered in a disabled state instead of producing an invalid URL.

Why?

In the current implementation, the link:

#/identities/create?account_id=${record.id}

can be generated even when record.id is null or undefined.

This results in:

  • Invalid navigation (e.g., account_id=null or undefined)
  • Downstream API failures (e.g., /accounts?id=eq.null)
  • Broken identity linking flow in the admin panel

This PR prevents those invalid states and improves robustness of the Accounts -> Identity workflow.

Fixes #6573

Examples

Before:

  • Clicking "Create Identity" could navigate to:
#/identities/create?account_id=undefined
  • Identity creation fails or behaves unexpectedly

After:

  • If record.id exists -> normal behavior

  • If missing -> link is disabled and no invalid navigation occurs

How to test

  1. Run the admin UI locally:
    npm run local

  2. Navigate to the Accounts admin page

  3. Open browser dev tools (Console)

  4. Temporarily modify the link by simulating a missing record id:

    • In the Elements panel, find a "Create Identity" link
    • Edit the href to:
      #/identities/create?account_id=
  5. Click the link

Before this fix:

  • The app attempts to navigate with an invalid account_id
  • This can result in API errors (e.g. /accounts?id=eq.null)

After this fix:

  • The link is not rendered / is disabled when account_id is missing
  • No invalid navigation occurs

Documentation of functionality

No documentation of changes required. This is a UI robustness fix.

Limitations

  • This PR guards against invalid record.id at the UI level only
  • It does not address upstream causes of missing record.id (if any exist)

Alternative implementations considered

Allowing navigation but handling null account_id downstream

  • Rejected because it allows invalid API calls and poor UX
    Silently not rendering the link

  • Rejected in favor of a visible but disabled UI for clarity

Open questions

None

Additional details or related context

*This change improves resilience of admin workflows involving identity creation

  • Keeps behavior consistent with expectations in React Admin-style UIs

Parts of this change were developed with the assistance of an AI tool (ChatGPT), particularly for debugging guidance and refining the implementation. The final code and testing were reviewed and validated manually.

@DougReeder DougReeder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the directions for reproducing the issue don't appear to be complete

Comment thread admin/src/react-components/fields.js Outdated
<a href={`#/identities/create?account_id=${record.id}`} className={classes.fieldLink}>
Create Identity
</a>
) : (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not syntactically correct JavaScript

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty. Fixed the JSX syntax issue and simplified the guard for missing record.id.

Also updated the test steps for clearer reproduction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failure to link an identity to an already existing account

2 participants