Skip to content

Commit

Permalink
Add schema check for two factor authentication columns in migration file
Browse files Browse the repository at this point in the history
  • Loading branch information
alibori committed Jan 7, 2025
1 parent 48fb1eb commit dc92413
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,27 @@
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->text('two_factor_secret')
->after('password')
->nullable();

$table->text('two_factor_recovery_codes')
->after('two_factor_secret')
->nullable();
if (! Schema::hasColumns(
'users',
[
'two_factor_secret',
'two_factor_recovery_codes',
'two_factor_confirmed_at',
]
)) {
$table->text('two_factor_secret')
->after('password')
->nullable();

if (Fortify::confirmsTwoFactorAuthentication()) {
$table->timestamp('two_factor_confirmed_at')
->after('two_factor_recovery_codes')
$table->text('two_factor_recovery_codes')
->after('two_factor_secret')
->nullable();

if (Fortify::confirmsTwoFactorAuthentication()) {
$table->timestamp('two_factor_confirmed_at')
->after('two_factor_recovery_codes')
->nullable();
}
}
});
}
Expand Down

0 comments on commit dc92413

Please sign in to comment.