rawilk / profile-filament-plugin

Profile & MFA starter kit for filament.
https://randallwilk.dev/docs/profile-filament-plugin
MIT License
10 stars 3 forks source link

Delete Function Error in DeleteAccount #9

Closed ketchalegend closed 5 months ago

ketchalegend commented 6 months ago

profile-filament-plugin Version

v0.2.1

Laravel Version

v10.10

Bug description

Bug Report: Delete Function Error in Plugin

Issue Description:

I encountered a minor bug while utilizing the delete function in my project. The specific issue arises with the label handling, where appending **?? '**' was necessary to avoid an error.

Error Log:

The following error was logged:

local.ERROR: Attempt to read property "email" on null {"view":{"view":"/Users/xxxxx/vendor/filament/forms/resources/views/components/field-wrapper/index.blade.php","data":[]},"exception":"[object] (Spatie\LaravelIgnition\Exceptions\ViewException(code: 0): Attempt to read property "email" on null at /Users/xxxxx/vendor/rawilk/profile-filament-plugin/src/Livewire/DeleteAccount.php:61)

Affected Code:

Here is the snippet of code where the issue occurs:

protected function getEmailInput(): Component
{
    return TextInput::make('email')
        /** @phpstan-ignore-next-line */
        ->label(fn () => __('profile-filament::pages/settings.delete_account.actions.delete.email_label', ['email' => Filament::auth()->user()->email **?? '**']))
        ->required()
        ->email()
        ->rules([
            fn (): Closure => function (string $attribute, $value, Closure $fail) {
                /** @phpstan-ignore-next-line */
                if (Str::lower($value) !== Str::lower(Filament::auth()->user()->email)) {
                    $fail(__('profile-filament::pages/settings.delete_account.actions.delete.incorrect_email'));
                },
        ]);
}

Steps to reproduce

Steps to Reproduce the Delete Function Error

  1. Initial Setup:

    • Ensure you are working with the specific version of the plugin where the issue was observed.
    • Set up the necessary environment that mirrors the conditions under which the bug was initially encountered.
  2. Navigate to the Relevant Section:

    • Go to the part of the application where the delete functionality is implemented.
  3. Trigger the Delete Function:

    • Perform the actions that typically lead to the invocation of the delete function. This could be clicking a delete button or selecting an option from a menu.
  4. Observe the Error:

    • At this point, you should encounter the specific error as mentioned in the bug report.
    • The error message should be similar to the one logged: Attempt to read property "email" on null.
  5. Check the Error Log:

    • Review the error log for details similar to the following:
      local.ERROR: Attempt to read property "email" on null ...
    • This log can help in pinpointing the exact location and nature of the issue.
  6. Review the Code:

    • Examine the code section where the error is occurring, particularly focusing on the label handling in the getEmailInput() method.
  7. Attempt a Workaround:

    • Try adding **?? '**' to the label as a temporary fix and observe if the error persists.

Relevant log output

local.ERROR: Attempt to read property "email" on null ...
rawilk commented 5 months ago

I'm fixing this in PR #15, and it will be included in the next pre-release. There will be breaking changes in this next release, however, so you'll need to make sure you read over the docs if you're adding custom pages or doing anything like that.

rawilk commented 5 months ago

I'm going to close this issue, since it should be resolved in v0.3.0. Feel free to re-open if problems still persist.