File tree Expand file tree Collapse file tree 6 files changed +25
-12
lines changed Expand file tree Collapse file tree 6 files changed +25
-12
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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];
Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 55use Carbon \CarbonInterval ;
66use DateInterval ;
77use Exception ;
8+ use Illuminate \Support \Arr ;
89use InvalidArgumentException ;
910
1011class 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}
You can’t perform that action at this time.
0 commit comments