Skip to content

Commit f441121

Browse files
committedMar 15, 2025·
Don't cache if a user is unauthorized to access Nova
Closes #3675
1 parent 57541bb commit f441121

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed
 

‎app/Providers/NovaServiceProvider.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,17 @@ protected function routes(): void
103103
#[\Override]
104104
protected function gate(): void
105105
{
106-
Gate::define('viewNova', static fn (User $user): bool => Cache::remember(
107-
'can_access_nova_'.$user->uid,
108-
now()->addDay(),
109-
static fn (): bool => $user->can('access-nova')
110-
));
106+
Gate::define('viewNova', static function (User $user): bool {
107+
if (Cache::get('can_access_nova_'.$user->uid, false) === true) {
108+
return true;
109+
} elseif ($user->can('access-nova')) {
110+
Cache::put('can_access_nova_'.$user->uid, true);
111+
112+
return true;
113+
} else {
114+
return false;
115+
}
116+
});
111117
}
112118

113119
/**

0 commit comments

Comments
 (0)