Skip to content

Commit

Permalink
Merge pull request #35 from dm-pf/master
Browse files Browse the repository at this point in the history
Make tailwind play nicely with Nova dark mode
  • Loading branch information
dniccum authored Aug 10, 2023
2 parents a932bb4 + cc76736 commit ee66594
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 14 deletions.
13 changes: 12 additions & 1 deletion config/novadocumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,15 @@

'home' => 'documentation/home.md',

];
/*
|--------------------------------------------------------------------------
| Login Route
|--------------------------------------------------------------------------
|
| The route that the user will be redirected to if they are not authenticated.
| If no route is provided, a 403 error will be returned.
|
*/

'login_route' => null,
];
2 changes: 1 addition & 1 deletion dist/css/tool.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/tool.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"/js/tool.js": "/js/tool.js",
"/atomDark.js": "/atomDark.js?id=f56ce784fa5895ba4747",
"/atom.js": "/atom.js?id=60b6e627f812617c190a",
"/monokai.js": "/monokai.js?id=e710c2dd8b4bbca5f350",
"/gradientDark.js": "/gradientDark.js?id=055add45f40b2c8e1538",
"/gradient.js": "/gradient.js?id=31c6a1d136619e153436",
"/githubDark.js": "/githubDark.js?id=8d7a51e52a7816ce08c1",
"/github.js": "/github.js?id=107b829682caf275ed63",
"/atomDark.js": "/atomDark.js?id=f6df2ba88ef374f56d86",
"/atom.js": "/atom.js?id=d3adf080cc103c06801c",
"/monokai.js": "/monokai.js?id=3df90070bb1b171a1c35",
"/gradientDark.js": "/gradientDark.js?id=9bc2cd3bf4be89695e1e",
"/gradient.js": "/gradient.js?id=5b299f51cf787299e7a5",
"/githubDark.js": "/githubDark.js?id=bcab67b5baf9d9a18649",
"/github.js": "/github.js?id=c8a81d2e7a375ca1fb97",
"/css/tool.css": "/css/tool.css"
}
23 changes: 22 additions & 1 deletion src/Http/Middleware/Authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Dniccum\NovaDocumentation\Http\Middleware;

use Dniccum\NovaDocumentation\NovaDocumentation;
use Laravel\Nova\Nova;

class Authorize
{
Expand All @@ -15,6 +16,26 @@ class Authorize
*/
public function handle($request, $next)
{
return resolve(NovaDocumentation::class)->authorize($request) ? $next($request) : abort(403);
$tool = collect(Nova::registeredTools())->first([$this, 'matchesTool']);

return optional($tool)->authorize($request)
? $next($request)
: $this->handleUnauthorizedRequest($request);
}

public function matchesTool($tool)
{
return $tool instanceof NovaDocumentation;
}

protected function handleUnauthorizedRequest($request)
{
$loginRoute = config('novadocumentation.login_route');

if ($loginRoute && auth()->guest()) {
return redirect()->guest(route($loginRoute));
}

abort(403);
}
}
2 changes: 1 addition & 1 deletion src/ToolServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function routes()
return;
}

Route::middleware(['nova', Authorize::class])
Nova::router(['nova', Authorize::class])
->prefix(\Str::finish(config('nova.path'), '/').$this->prefix)
->group(__DIR__.'/../routes/inertia.php');
}
Expand Down
4 changes: 2 additions & 2 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
corePlugins: {
preflight: false,
},
darkMode: 'media',
darkMode: ['class', 'html[class~=\'dark\']'],
theme: {
extend: {
colors: {
Expand Down Expand Up @@ -160,4 +160,4 @@ module.exports = {
require('@tailwindcss/typography'),
],
prefix: 'doc-',
};
};

0 comments on commit ee66594

Please sign in to comment.