mirror of
https://github.com/tiennm99/coolify.git
synced 2026-04-20 05:20:56 +00:00
feat(user): implement session deletion on password reset
This commit is contained in:
34
app/Traits/DeletesUserSessions.php
Normal file
34
app/Traits/DeletesUserSessions.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
trait DeletesUserSessions
|
||||
{
|
||||
/**
|
||||
* Delete all sessions for the current user.
|
||||
* This will force the user to log in again on all devices.
|
||||
*/
|
||||
public function deleteAllSessions(): void
|
||||
{
|
||||
// Invalidate the current session
|
||||
Session::invalidate();
|
||||
Session::regenerateToken();
|
||||
DB::table('sessions')->where('user_id', $this->id)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Boot the trait.
|
||||
*/
|
||||
protected static function bootDeletesUserSessions()
|
||||
{
|
||||
static::updated(function ($user) {
|
||||
// Check if password was changed
|
||||
if ($user->isDirty('password')) {
|
||||
$user->deleteAllSessions();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user