laravel / nova-issues

554 stars 34 forks source link

TypeError: Cannot read properties of undefined (reading 'length') #5298

Closed GlennBags closed 1 year ago

GlennBags commented 1 year ago

Description:

Trying to utilize Policies to control access using a role column on the User model and UserRole enum to compare the values. Before populating the UserPolicy, was able to access fine. After, my "SuperAdmin" was able to access everything just fine. After logging in with a "Support" role that would have view, but not edit, started to see nothing render. Found errors in console: TypeError: Cannot read properties of undefined (reading 'length') at Proxy.shouldShowCards (Dashboard.vue:108:25) Cicking shows:

    shouldShowCards() {
      return this.cards.length > 0
    },

I do not have a Card model (saw other closed issue related to that).

Detailed steps to reproduce the issue on a fresh Nova installation:

created UserRole enum that is used to in the UserPolicy like:

    public function viewAny(User $user): Response|bool
    {
        return $user->role === UserRole::SuperAdmin->value
                      || $user->role === UserRole::Admin->value
                      || $user->role === UserRole::Support->value;
    }
crynobone commented 1 year ago

Unable to reproduce the issue, please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

GlennBags commented 1 year ago

Something have I've noticed is I think it has to do with our test accounts having simple passwords, and when I login via Nova, I get a popup about how bad the password is and that might be interrupting things? If I login via our app, and navigate to Nova from there, all is fine. When I logout via Nova, then log in via Nova, I get the popup regarding the password, and then I get the issue with the card being undefined.

crynobone commented 1 year ago

Something have I've noticed is I think it has to do with our test accounts having simple passwords, and when I login via Nova, I get a popup about how bad the password is and that might be interrupting things?

This is irrelevant to the issue, if you still believe then we really need a full reproducing repository in order to confirm it.

GlennBags commented 1 year ago

Closing because I don't think it's necessarily related to your code, but the popup that I'm getting about passwords. I'll create another ticket in the future if I find something different. Either way, this is company code, so I cannot give a "full reproducing repository".