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]: Attempt to read property "value" on null error #47

Closed
enessvg opened this issue Sep 29, 2024 · 22 comments · Fixed by #49
Closed

[Bug]: Attempt to read property "value" on null error #47

enessvg opened this issue Sep 29, 2024 · 22 comments · Fixed by #49
Assignees
Labels
bug Something isn't working

Comments

@enessvg
Copy link

enessvg commented Sep 29, 2024

What happened?

hello, I installed the plugin and opened 2fa, then when I tried to log in, I got an error like this:
Attempt to read property “value” on null

In order to resolve this error
vendor\vormkracht10\filament-2fa\src\Http\Livewire\Auth\LoginTwoFactor.php
In line 44 $this->twoFactorType = $this->challengedUser->two_factor_type->value;
It worked when I removed the value from the code, what is this caused by? can you check?

Translated with DeepL.com (free version)

How to reproduce the bug

Bu hatayı çözmek içinde
vendor\vormkracht10\filament-2fa\src\Http\Livewire\Auth\LoginTwoFactor.php
44. satırdaki $this->twoFactorType = $this->challengedUser->two_factor_type->value;
kodundan valueyi kaldırınca çalıştı bu neyden kaynaklanıyor? kontrol edermisiniz?

Package Version

1.6^

PHP Version

8.2.4

Laravel Version

11.0.0

Which operating systems does with happen with?

Windows

Notes

No response

@enessvg enessvg added the bug Something isn't working label Sep 29, 2024
@Baspa
Copy link
Member

Baspa commented Sep 29, 2024

Did you follow all the installation steps from the readme? @enessvg

@enessvg
Copy link
Author

enessvg commented Sep 29, 2024

@Baspa Yes

@Baspa
Copy link
Member

Baspa commented Sep 29, 2024

Can you provide me a reproduction repository? Then I'll be happy to help @enessvg

@enessvg
Copy link
Author

enessvg commented Sep 29, 2024

I can't provide it right now, but I can leave photos like this:
image

Deleted value code:
$this->twoFactorType = $this->challengedUser->two_factor_type;

image

@Baspa Maybe it's my fault, I'll install it in another project and try again. But as I said, I did the installation completely by following https://filamentphp.com/plugins/vormkracht10-2fa

@Baspa
Copy link
Member

Baspa commented Sep 29, 2024

Did you run migrations? Can you show me your user model and did you setup 2FA for the user? @enessvg

@enessvg
Copy link
Author

enessvg commented Sep 29, 2024

Did you run migrations? Can you show me your user model and did you setup 2FA for the user? @enessvg

Yes, I've run migrations. @Baspa

User.php:

use Laravel\Fortify\TwoFactorAuthenticatable;
use Vormkracht10\TwoFactorAuth\Enums\TwoFactorType;

use HasFactory, Notifiable, HasRoles, HasPanelShield, TwoFactorAuthenticatable;

protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'password' => 'hashed',
            'two_factor_type' => TwoFactorType::class,
        ];
    }

@Baspa
Copy link
Member

Baspa commented Sep 29, 2024

I just did a fresh installation here and got no errors: https://github.com/Baspa/reproduction-repo

you can check my latest commit @enessvg

@enessvg
Copy link
Author

enessvg commented Sep 30, 2024

Okey, I will try to reinstall and try again, thanks.

I just did a fresh installation here and got no errors: https://github.com/Baspa/reproduction-repo

you can check my latest commit @enessvg

@Baspa
Copy link
Member

Baspa commented Oct 1, 2024

Any updates on this issue? @enessvg

@enessvg
Copy link
Author

enessvg commented Oct 2, 2024

@Baspa Sorry for not replying, I still haven't tried it, I will try it as soon as possible and write here

@tonypartridge
Copy link

I looked at using this package and got the same error, it would appear the casting doesn't cast null/empty two_factor_types. Ideally there should be either a default, or login if 2fa type is not set.

@Baspa
Copy link
Member

Baspa commented Oct 2, 2024

Thanks for checking both, will try to look for a fix later today @enessvg / @tonypartridge

@Baspa Baspa self-assigned this Oct 2, 2024
@Baspa
Copy link
Member

Baspa commented Oct 2, 2024

Did you guys install this package after already using Laravel Fortify? I guess this issue might happen when the user already has set the 2FA on their user but didn't use this package yet. Then the 2FA might be "enabled", which causes the user to be redirected to the 2FA login page, but there is no 2FA type set.

If that's the case I might need to change the documentation.

@enessvg / @tonypartridge

@tonypartridge
Copy link

tonypartridge commented Oct 2, 2024 via email

@enessvg
Copy link
Author

enessvg commented Oct 2, 2024

Did you guys install this package after already using Laravel Fortify? I guess this issue might happen when the user already has set the 2FA on their user but didn't use this package yet. Then the 2FA might be "enabled", which causes the user to be redirected to the 2FA login page, but there is no 2FA type set.

If that's the case I might need to change the documentation.

@enessvg / @tonypartridge

https://filamentphp.com/plugins/vormkracht10-2fa#installation
I followed what was said here and got that error
So yes I installed fortify

@Baspa Baspa linked a pull request Oct 4, 2024 that will close this issue
@Baspa
Copy link
Member

Baspa commented Oct 4, 2024

@enessvg / @tonypartridge after I merge #49 in a few minutes you should update the package and re-run php artisan filament-two-factor-auth:install.

Remove previous migration from this package before running the install command. When you run the migrations through the install command again it will now prompt if you want to update existing users to set their missing two_factor_type. It will default to authenticator.

@enessvg
Copy link
Author

enessvg commented Oct 4, 2024

@Baspa Thank you, I'm glad I wrote this error here

@Baspa Baspa closed this as completed in #49 Oct 4, 2024
@tonypartridge
Copy link

Good stuff, will review.

@tonypartridge
Copy link

only thoughts are:

Would you like us to set the two factor type to "authenticator" for existing users? (yes/no)

should be

Would you like us to set the two factor type to "authenticator" for users that previously used 2FA in fortify? (yes/no)

@tonypartridge
Copy link

I tried this and disabled normal 2fa and then tried email but never got the email even with queue working.

@Baspa
Copy link
Member

Baspa commented Oct 4, 2024

only thoughts are:

Would you like us to set the two factor type to "authenticator" for existing users? (yes/no)

should be

Would you like us to set the two factor type to "authenticator" for users that previously used 2FA in fortify? (yes/no)

Feel free to submit a PR! @tonypartridge

@Baspa
Copy link
Member

Baspa commented Oct 4, 2024

I tried this and disabled normal 2fa and then tried email but never got the email even with queue working.

What are the exact steps you did? Have you set a two_factor_type on the user? Does it has its email set?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants