Skip to content

Commit b6b4813

Browse files
authored
Merge pull request #1 from laravelcm/update-middleware
Update session check on middleware
2 parents 668da2a + d28b97d commit b6b4813

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Tests
1+
name: tests
22

33
on: push
44

src/DataObject/Connection.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
final class Connection
88
{
99
public function __construct(
10-
public string $connectionType,
11-
public int $autonomousSystemNumber,
12-
public string $autonomousSystemOrganization,
13-
public string $ispName,
14-
public string $organizationName,
10+
public ?string $connectionType,
11+
public ?int $autonomousSystemNumber,
12+
public ?string $autonomousSystemOrganization,
13+
public ?string $ispName,
14+
public ?string $organizationName,
1515
) {
1616
}
1717
}

src/Middleware/AbstractIpGeolocation.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,25 @@ public function handle($request, Closure $next): mixed
2424
(new IpGeolocation($request))->initialize()
2525
);
2626

27-
session()->put('abstract-ip-geolocation', $response);
27+
$this->manageSession($response);
2828

2929
return $next($request);
3030
}
31+
32+
public function manageSession(GeolocationData $geolocation): void
33+
{
34+
$sessionKey = 'abstract-ip-geolocation';
35+
36+
if (session()->exists($sessionKey)) {
37+
/** @var GeolocationData $currentValue */
38+
$currentValue = session()->get($sessionKey);
39+
40+
if ($currentValue->ipAddress !== $geolocation->ipAddress) {
41+
session()->forget($sessionKey);
42+
session()->put($sessionKey, $geolocation);
43+
}
44+
} else {
45+
session()->put($sessionKey, $geolocation);
46+
}
47+
}
3148
}

0 commit comments

Comments
 (0)