born05 / craft-twofactorauthentication

Craft plugin for two-factor or two-step login using Time Based OTP.
MIT License
36 stars 26 forks source link

Table 'twofactorauthentication_usertoken' doesn't exist #86

Closed dletsche closed 8 months ago

dletsche commented 8 months ago

First time user of this plugin.

It installed fine and I could access the "Two-Factor Authentication" CP page, but "Step 3: Verify the code from your device" wasn't working.

I spotted this error in the logs...

[web.ERROR] [yii\db\Exception] PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'lamp.twofactorauthentication_usertoken' doesn't exist in /app/vendor/yiisoft/yii2/db/Command.php:1302

I'm a bit inexperienced with creating plugins, but I believe the table creation in https://github.com/born05/craft-twofactorauthentication/blob/craft-4/src/migrations/m240208_094536_create_usertoken_table.php also needs to be added to https://github.com/born05/craft-twofactorauthentication/blob/craft-4/src/migrations/Install.php to cover fresh installs.

In case it's helpful, here are my system details: PHP version 8.2.5 OS version Linux 6.5.11-linuxkit Database driver & version MySQL 8.0.19 Craft edition & version Craft Pro 4.7.2.1 Yii version 2.0.48.1

Let me know if more info would be helpful.

roelvanhintum commented 8 months ago

@dletsche thanks for the issue! This should be fixed in 3.3.5 You probably need to uninstall the plugin, update and perform the install again.

svondervoort commented 7 months ago

@roelvanhintum Maybe related to this issue on existing sites we get the error with the m240208_094536_create_usertoken_table migration saying:

Table 'twofactorauthentication_usertoken' already exists

Updating from 3.3.2 => 3.3.7

roelvanhintum commented 7 months ago

@svondervoort did that migration fail before? It only runs on fresh install or migration, but not both.

svondervoort commented 7 months ago

@svondervoort did that migration fail before? It only runs on fresh install or migration, but not both.

Thanks for replying.

I'm not sure, I only see 2 migrations in the migrations table of the live DB. Now that I check the live DB I also don't see the usertoken table exists. So not sure where it went wrong. I currently only tried it locally but will keep an eye out when deploying to a staging environment. For now I fixed the migration failing by manually deleting the usertoken table and then updating the plugin.