Skip to content

Commit cb1fd11

Browse files
wip
1 parent 10b58d0 commit cb1fd11

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ return [
147147
| You can override this by setting a specific guard name (e.g., 'api').
148148
|
149149
*/
150-
'guard' => null,
150+
'guards' => [],
151151
];
152152
```
153153

config/cloudfront-cookies.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@
113113

114114
/*
115115
|--------------------------------------------------------------------------
116-
| Authentication Guard
116+
| Authentication Guards
117117
|--------------------------------------------------------------------------
118118
|
119-
| The authentication guard to use when checking if a user is authenticated
119+
| The authentication guards to use when checking if a user is authenticated
120120
| before setting CloudFront cookies.
121121
| If not set, the package will use the default authentication guard.
122122
|
123123
| You can override this by setting a specific guard name (e.g., 'api').
124124
|
125125
*/
126-
'guard' => null,
126+
'guards' => [],
127127
];

src/CloudfrontCookies.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function clear(): void
6363
Cookie::queue(
6464
name: $name,
6565
value: '',
66-
minutes: -2628000, // -5 years to ensure deletion
66+
minutes: -2628000,
6767
path: '/',
6868
domain: Config::getCookieDomain(),
6969
secure: true,

src/CloudfrontCookiesServiceProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public function packageBooted(): void
3434
])
3535
));
3636

37-
// Register logout event listener
3837
Event::listen(
3938
Logout::class,
4039
ClearCloudfrontCookiesOnLogout::class

src/Http/Middleware/SignCloudfrontCookies.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ class SignCloudfrontCookies
1717
*/
1818
public function handle(Request $request, Closure $next)
1919
{
20-
// Check if CloudFront cookies are enabled
2120
if (! Config::isEnabled()) {
2221
return $next($request);
2322
}
2423

25-
// Only set cookies for authenticated users
26-
$guard = Config::getGuard();
27-
if (auth($guard)->check()) {
24+
$guards = Config::getGuards();
25+
$isAuthenticated = collect($guards)
26+
->contains(fn (string $guard) => (
27+
auth($guard)->check()
28+
));
29+
30+
if ($isAuthenticated) {
2831
CloudfrontCookies::queue();
2932
}
3033

src/Support/Config.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Carbon\CarbonInterval;
66
use DateInterval;
77
use Exception;
8+
use Illuminate\Support\Arr;
89
use InvalidArgumentException;
910

1011
class Config
@@ -100,8 +101,18 @@ public static function getCookieDuration(): int
100101
return (int) self::getExpirationInterval()->totalMinutes;
101102
}
102103

103-
public static function getGuard(): ?string
104+
public static function getGuards(): ?array
104105
{
105-
return config('cloudfront-cookies.guard');
106+
$gurads = config('cloudfront-cookies.guards');
107+
108+
if (blank($gurads)) {
109+
return null;
110+
}
111+
112+
if (is_string($gurads) || is_array($gurads)) {
113+
return Arr::wrap($gurads);
114+
}
115+
116+
throw new InvalidArgumentException;
106117
}
107118
}

0 commit comments

Comments
 (0)