Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with Auth::user() in addNote class #73

Open
mateusz-peczkowski opened this issue Apr 25, 2024 · 1 comment
Open

Bug with Auth::user() in addNote class #73

mateusz-peczkowski opened this issue Apr 25, 2024 · 1 comment

Comments

@mateusz-peczkowski
Copy link

mateusz-peczkowski commented Apr 25, 2024

Hi.

I found a bug in version 3.1.0 (latest). Don't know if this was on old releases as well.

The issue is with column "created_by".

This column in DB is filled only when default guard === nova guard for auth :) I had different for frontend and different for nova and that's why I found this issue.

In Models/Note.php you have:

public function createdBy()
    {
        $provider = 'users';
        if (config('nova.guard')) $provider = config('auth.guards.' . config('nova.guard') . '.provider');
        $userClass = config('auth.providers.' . $provider . '.model');
        return $this->belongsTo($userClass, 'created_by');
    }

which is OK but then under trait HasNotes you are using:

$user = $user ? Auth::user() : null;
        return $this->notes()->create([
            'text' => $note,
            'created_by' => isset($user) ? $user->id : null,
            'system' => $system,
        ]);

Without providing guard Auth is returning default, in my case it was api while nova auth was web. It should be rather Auth::guard(config('nova.guard'))->user()

Steps to reproduce:

  • Install nova project
  • change config => nova.guard to web
  • change config => auth.defaults.guard to API (must use different table than web guard probably)
  • Try to save note (it will appear as "User" instead of your nova user data)
@mateusz-peczkowski
Copy link
Author

mateusz-peczkowski commented Apr 26, 2024

I made a fork and submitted pull request for this fix #74

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

No branches or pull requests

1 participant