Skip to content

Fix ShareInertiaData middleware for Eloquent strict mode when 2FA is disabled#1319

Merged
taylorotwell merged 1 commit intolaravel:3.xfrom
onlime:fix-inertia-2fa-missing-attribute
Jun 7, 2023
Merged

Fix ShareInertiaData middleware for Eloquent strict mode when 2FA is disabled#1319
taylorotwell merged 1 commit intolaravel:3.xfrom
onlime:fix-inertia-2fa-missing-attribute

Conversation

@onlime
Copy link
Contributor

@onlime onlime commented Jun 7, 2023

When we don't want to have 2FA Fortify feature Features::twoFactorAuthentication() enabled, we usually don't have any two_factor_* (namely two_factor_secret) columns on our User model / in our migration. In that case, we couldn't enable Eloquent Strictness, which is recommended for non-production environments. Enabled Model::preventSilentlyDiscardingAttributes() would throw the following MissingAttributeException exception:

The attribute [two_factor_secret] either does not exist or was not retrieved for model [App\Models\User].

This happens on Http/Middleware/ShareInertiaData.php#L57 when trying to access the non-existing attribute:

'two_factor_enabled' => ! is_null($user->two_factor_secret),

This is a simple fix by adding an additional check if the 2FA feature is enabled.

…entAccessingMissingAttributes) on disabled 2FA
@taylorotwell taylorotwell merged commit c65656c into laravel:3.x Jun 7, 2023
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

Successfully merging this pull request may close these issues.

2 participants