Skip to content

Commit

Permalink
Ensure code is deleted with user.
Browse files Browse the repository at this point in the history
  • Loading branch information
theriftlab committed Oct 27, 2022
1 parent a57857c commit 9627fb2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Concerns/Mfa.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Str;
use Mfa\Contracts\MfaUser;
use Mfa\Models\MfaCode;

trait Mfa
Expand Down Expand Up @@ -62,4 +63,17 @@ public function checkMfaCode(string $code): bool
{
return $this->mfaCode?->code === $code;
}

/**
* The "booted" method of the model.
* Delete the MFA code record on user deletion.
*
* @return void
*/
protected static function booted()
{
static::deleted(function (MfaUser $user) {
$user->mfaCode?->delete();
});
}
}

0 comments on commit 9627fb2

Please sign in to comment.