Skip to content

Commit

Permalink
Use setUser() all the time instead of login()
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed May 8, 2024
1 parent ee70226 commit d083007
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
3 changes: 3 additions & 0 deletions packages/actions/docs/10-upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ protected function setUp(): void

Ideally, you should avoid overriding the `make()` method altogether as there are alternatives like `setUp()`, and doing so causes your code to be brittle if Filament decides to introduce new constructor parameters in the future.

#### Authenticating the user inside the import and export jobs

In v3, the `Illuminate\Auth\Events\Login` event was fired from the import and export jobs, to set the current user. This is no longer the case in v4: the user is authenticated, but that event is not fired, to avoid running any listeners that should only run for actual user logins.
6 changes: 1 addition & 5 deletions packages/actions/src/Exports/Jobs/ExportCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ public function handle(): void
/** @var Authenticatable $user */
$user = $this->export->user;

if (method_exists(auth()->guard(), 'login')) {
auth()->login($user);
} else {
auth()->setUser($user);
}
auth()->setUser($user);

$exceptions = [];

Expand Down
6 changes: 1 addition & 5 deletions packages/actions/src/Imports/Jobs/ImportCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ public function handle(): void
/** @var Authenticatable $user */
$user = $this->import->user;

if (method_exists(auth()->guard(), 'login')) {
auth()->login($user);
} else {
auth()->setUser($user);
}
auth()->setUser($user);

$exceptions = [];

Expand Down

0 comments on commit d083007

Please sign in to comment.