diff --git a/lang/en/default.php b/lang/en/default.php index 5799a6f..d964aea 100644 --- a/lang/en/default.php +++ b/lang/en/default.php @@ -85,6 +85,7 @@ 'email_not_found' => 'We were unable to find a registered user with this email address.', 'employee_already_belongs_to_company' => 'This employee already belongs to the company.', 'employee_already_invited' => 'This employee has already been invited to the company.', + 'generic_error' => 'An error occurred while processing your request.', 'invalid_password' => 'The password you entered is invalid.', 'no_email_with_account' => 'No email address is associated with this :Provider account. Please try a different account.', 'password_does_not_match' => 'The provided password does not match your current password.', diff --git a/resources/views/profile/connected-accounts-form.blade.php b/resources/views/profile/connected-accounts-form.blade.php index dd32014..f6b9949 100644 --- a/resources/views/profile/connected-accounts-form.blade.php +++ b/resources/views/profile/connected-accounts-form.blade.php @@ -42,7 +42,7 @@ @endif - @if ($this->user->password !== null || $this->accounts->count() > 1) + @if ($this->user?->password !== null || $this->accounts->count() > 1) {{ __('filament-companies::default.buttons.remove') }} diff --git a/src/Http/Controllers/OAuthController.php b/src/Http/Controllers/OAuthController.php index 1bb051a..19cc252 100644 --- a/src/Http/Controllers/OAuthController.php +++ b/src/Http/Controllers/OAuthController.php @@ -139,6 +139,10 @@ protected function handleError(Request $request): RedirectResponse { $error_description = $request->input('error_description'); + if ($error_description === null) { + $error_description = __('filament-companies::default.errors.generic_error'); + } + $targetUrl = $this->guard->check() ? filament()->getHomeUrl() : null; if ($targetUrl === null) { diff --git a/src/Http/Livewire/ConnectedAccountsForm.php b/src/Http/Livewire/ConnectedAccountsForm.php index 7f81c33..13fd5e8 100644 --- a/src/Http/Livewire/ConnectedAccountsForm.php +++ b/src/Http/Livewire/ConnectedAccountsForm.php @@ -56,8 +56,10 @@ public function confirmRemove(string | int $accountId): void */ public function setAvatarAsProfilePhoto(string | int $accountId): RedirectResponse | Redirector { - $account = Auth::user()->connectedAccounts - ->where('user_id', ($user = Auth::user())->getAuthIdentifier()) + $user = $this->user; + + $account = $this->user?->connectedAccounts + ->where('user_id', $user?->getAuthIdentifier()) ->where('id', $accountId) ->first(); @@ -74,7 +76,7 @@ public function setAvatarAsProfilePhoto(string | int $accountId): RedirectRespon public function removeConnectedAccount(string | int $accountId): void { DB::table('connected_accounts') - ->where('user_id', Auth::user()?->getAuthIdentifier()) + ->where('user_id', $this->user?->getAuthIdentifier()) ->where('id', $accountId) ->delete(); @@ -96,7 +98,11 @@ public function cancelConnectedAccountRemoval(): void */ public function getAccountsProperty(): Collection { - return Auth::user()->connectedAccounts + if ($this->user?->connectedAccounts === null) { + return collect(); + } + + return $this->user->connectedAccounts ->map(static function (ConnectedAccount $account) { return (object) $account->getSharedData(); }); diff --git a/src/Http/Livewire/CreateCompanyForm.php b/src/Http/Livewire/CreateCompanyForm.php index 2d41689..b12d329 100644 --- a/src/Http/Livewire/CreateCompanyForm.php +++ b/src/Http/Livewire/CreateCompanyForm.php @@ -30,7 +30,7 @@ public function createCompany(CreatesCompanies $creator): Response | Redirector { $this->resetErrorBag(); - $creator->create(Auth::user(), $this->state); + $creator->create($this->user, $this->state); $name = $this->state['name']; diff --git a/src/Http/Livewire/SetPasswordForm.php b/src/Http/Livewire/SetPasswordForm.php index 8219d57..3737aa7 100644 --- a/src/Http/Livewire/SetPasswordForm.php +++ b/src/Http/Livewire/SetPasswordForm.php @@ -30,7 +30,7 @@ public function setPassword(SetsUserPasswords $setter): void { $this->resetErrorBag(); - $setter->set(Auth::user(), $this->state); + $setter->set($this->user, $this->state); $this->state = [ 'password' => '', @@ -39,7 +39,7 @@ public function setPassword(SetsUserPasswords $setter): void if (FilamentCompanies::hasNotificationsFeature()) { if (method_exists($setter, 'passwordSet')) { - $setter->passwordSet(Auth::user(), $this->state); + $setter->passwordSet($this->user, $this->state); } else { $this->passwordSet(); } diff --git a/src/Http/Livewire/UpdatePasswordForm.php b/src/Http/Livewire/UpdatePasswordForm.php index b630ab2..5a85175 100644 --- a/src/Http/Livewire/UpdatePasswordForm.php +++ b/src/Http/Livewire/UpdatePasswordForm.php @@ -30,11 +30,11 @@ public function updatePassword(UpdatesUserPasswords $updater): void { $this->resetErrorBag(); - $updater->update(Auth::user(), $this->state); + $updater->update($this->user, $this->state); if (session() !== null) { session()->put([ - 'password_hash_' . Auth::getDefaultDriver() => Auth::user()?->getAuthPassword(), + 'password_hash_' . Auth::getDefaultDriver() => $this->user?->getAuthPassword(), ]); } @@ -46,7 +46,7 @@ public function updatePassword(UpdatesUserPasswords $updater): void if (FilamentCompanies::hasNotificationsFeature()) { if (method_exists($updater, 'passwordUpdated')) { - $updater->passwordUpdated(Auth::user(), $this->state); + $updater->passwordUpdated($this->user, $this->state); } else { $this->passwordUpdated(); } diff --git a/src/Http/Livewire/UpdateProfileInformationForm.php b/src/Http/Livewire/UpdateProfileInformationForm.php index 30520b5..618d5cc 100644 --- a/src/Http/Livewire/UpdateProfileInformationForm.php +++ b/src/Http/Livewire/UpdateProfileInformationForm.php @@ -36,7 +36,7 @@ class UpdateProfileInformationForm extends Component */ public function mount(): void { - $user = Auth::user(); + $user = $this->user; $this->state = ['email' => $user?->email, ...$user?->withoutRelations()->toArray()]; } @@ -49,7 +49,7 @@ public function updateProfileInformation(UpdatesUserProfileInformation $updater) $this->resetErrorBag(); $updater->update( - Auth::user(), + $this->user, $this->photo ? [...$this->state, 'photo' => $this->photo] : $this->state @@ -61,7 +61,7 @@ public function updateProfileInformation(UpdatesUserProfileInformation $updater) if (FilamentCompanies::hasNotificationsFeature()) { if (method_exists($updater, 'profileInformationUpdated')) { - $updater->profileInformationUpdated(Auth::user(), $this->state); + $updater->profileInformationUpdated($this->user, $this->state); } else { $this->profileInformationUpdated(); } @@ -82,7 +82,7 @@ protected function profileInformationUpdated(): void */ public function deleteProfilePhoto(): void { - Auth::user()?->deleteProfilePhoto(); + $this->user?->deleteProfilePhoto(); } /** @@ -90,7 +90,7 @@ public function deleteProfilePhoto(): void */ public function sendEmailVerification(): void { - Auth::user()?->sendEmailVerificationNotification(); + $this->user?->sendEmailVerificationNotification(); $this->verificationLinkSent = true;