Implement device and IP tracking for users

Added Device and UserIp models and migrations to store device fingerprints and user IPs with expiration. Updated ShowSavingIp Livewire component and view to capture and persist both IP and device fingerprint. Introduced a scheduled command to clean expired user IPs and registered it in the console kernel. Removed the old migration for storing IPs directly on the users table.
This commit is contained in:
Juan Felipe Duarte
2025-10-25 09:18:56 -05:00
parent a558e393f2
commit 4a44dbc1c1
9 changed files with 168 additions and 42 deletions
@@ -1,23 +1,35 @@
<div
x-data="{
getIp() {
fetch('https://api.ipify.org/?format=json')
.then(res => res.json())
.then(data => {
$wire.emit('setIpAddress', data.ip);
})
.catch(err => console.error('Error obteniendo IP:', err));
async getData() {
try {
// Obtener IP pública
const ipRes = await fetch('https://api.ipify.org/?format=json');
const ipData = await ipRes.json();
// Cargar librería Fingerprint
const fpModule = await import('https://openfpcdn.io/fingerprintjs/v3');
const fp = await fpModule.load();
const result = await fp.get();
const fingerprint = result.visitorId;
// Emitir ambos valores a Livewire
$wire.emit('setDeviceData', { ip: ipData.ip, fingerprint });
} catch (e) {
console.error('Error obteniendo IP/Fingerprint:', e);
}
}
}"
x-init="getIp()"
x-init="getData()"
wire:poll.visible.delay.600000ms
class="py-4"
>
<p class="text-sm text-gray-600">
@if($ip_address)
Tu IP actual: <strong>{{ $ip_address }}</strong>
Tu IP actual: <strong>{{ $ip_address }}</strong><br>
ID del dispositivo: <strong>{{ $device_fingerprint }}</strong>
@else
Obteniendo IP...
Obteniendo IP y dispositivo...
@endif
</p>
</div>