saleem-hadad / larecipe

✏️ Write and ship beautiful documentation with your Laravel applications using MarkDown
https://larecipe.saleem.dev/
MIT License
2.41k stars 265 forks source link

Hide docs through auth flag in config not working in Nova #170

Closed christophrumpel closed 5 years ago

christophrumpel commented 5 years ago

Describe the bug I have a Nova installation and I'm using larecipe. I want to hide the docs from guests. I saw the auth settings in the config, but when I set auth to true I get this error about the login route:

Route [login] not defined

So I assume this is build to use Laravel default auth routes? This is probably different in Nova. Can I define the route to redirect myself? In my version of larecipe I still have these auth settings:

'settings' => [
        'auth'  => true,
        'auth_links' => [
            [
                'name' => '',
                'url' => '',
            ],
        ],
        'ga_id' => ''
    ],

But from what I saw this structure changed. Doe auth links still work?

To Reproduce Steps to reproduce the behavior:

  1. Install Laravel Nova
  2. Install LaRecipe
  3. Set auth key to true in the config
  4. Visit the /docs page

Expected behavior I should be redirected to a page that I define.

Screenshots

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Could also be a feature instead of a bug?

WillGoldstein commented 5 years ago

What version of larecipe are you on? Should be 2.2.0 I think which is a PR I did and that got accepted that lets you have way more flexibility in this subject. My docs update PR is ready to go but I’m waiting on @saleem-hadad to make a new branch first to pull into. I can probably help you with the changes in the meantime, though I’m not familiar with nova. I assume, like Spark, it’s got similar middleware since it’s laravel.

WillGoldstein commented 5 years ago

Also, did you remember to include middleware in your docs settings?

config/larecipe.php

    'docs'        => [
        'route'   => '/docs',
        'path'    => '/resources/docs',
        'landing' => 'overview',
        'middleware' => ['web'],
    ],

...

    'settings'       => [
        'auth'       => false,
        'ga_id'      => '',
        'middleware' => [
            'web'
        ],
    ],

The need for that is in my update for larecipe-docs I referred to in my previous comment.

In this case, since auth is set to false and I'm on the most recent version (2.2.0), Larecipe will route through the web middleware (and/or whatever other middleware I want). Obviously with custom middleware, I can have it route to anywhere I want. Further, you can use gates to get more granular with which docs to display to which people.

Note, this also allows for more complex permissions. I made this because I had the scenario where I needed to simultaneously show some of my docs to guests users (marketing), authenticated users (so they can learn the app), and admin users (so they can learn admin portions of the app).

christophrumpel commented 5 years ago

Hey @WillGoldstein,

thanks a lot for the detailed reply. Yes, I have been using version 2.2.0. I'm now using a custom middleware which was an easy fix. Thanks a lot for that hint. 👍

WillGoldstein commented 5 years ago

No problem @christophrumpel , also last I checked the composer package wasn’t updated with recent updates like the one I’m describing. #171

ITango commented 5 years ago

Hey @christophrumpel,

I am facing a similar issue, i.e. Nova installation together with Larecipe, where docs are visible to logged users only. I wonder if you could possibly give me some hints about the custom middleware you are using.

WillGoldstein commented 5 years ago

Hey @ITango , it’s middleware I made. Do you have the latest version? If so, I can help you.

For some reason the docs aren’t showing my PR:

https://github.com/saleem-hadad/larecipe-docs/pull/8

But you can read the code changes and probably get a good hint at how the new changes work.

ITango commented 5 years ago

Hey @WillGoldstein,

Thank you for your reply. I managed to get it working. Much appreciated.