wdelfuego / nova-wizard

A simple multi-step Wizard tool for Laravel Nova 4
Other
11 stars 5 forks source link

Getting 403 error after tutorial setup #3

Closed adrian-schnell closed 9 months ago

adrian-schnell commented 9 months ago

I tried to setup the wizard as shown in the documentation. Only thing I changed is the uri in the config file to setup/create-community. When clicking the link to open the wizard (embed as tool or direct link) I'm receiving 403.

wdelfuego commented 9 months ago

I've updated my local installation to use that same uri but everything keeps working, so the problem is not with the custom uri.

403 indicates an authorization / authentication problem; the issue might be related to your Nova path.

If you can answer the following questions we'll probably find the issue:

  1. What is the path option set to in config/nova.php?
  2. At what complete URL are you trying to open your calendar?
  3. Do you see the link to your "Create Community" wizard added to your Nova menu? If so, what path is it pointing to?
  4. Did you add the wizard link to the menu manually, or are you using Nova's automatic menu generation?
adrian-schnell commented 9 months ago

Thanks for your quick reply.

  1. path ist set to 'path' => '/admin_backend',
  2. open calendar? don't understand what you mean 🫣
  3. it's pointing to https://domain.test/admin_backend/setup/create-community
  4. right now I added it manually: MenuItem::link(__('backend/sidebar_menu.community_wizard'), NovaWizard::pathToWizard('create-community')),

when adding it as tool with new NovaWizard('create-community') it links to https://domain.test/admin_backend/nova-wizard

and inside the wizard config:

return [
    'create-community' => [
        'class'       => CreateCommunityWizard::class,
        'uri'         => 'setup/create-community',
        'windowTitle' => 'Create your Community now',
    ],
];
wdelfuego commented 9 months ago

Sorry for the confusion, I've been working too much on nova-calendar 🙈.

I meant "2. At what URL are you trying to open your wizard?" I guess the same URL as you mentioned under 3?

wdelfuego commented 9 months ago

I've recreated your setup but everything works for me.

However, I do get a 403 if I remove the Tool from the array returned by tools() in the NovaServiceProvider.

Can you check again if you performed step 4 of the installation instructions completely? I.e., are you including new NovaWizard('create-community') in the array returned by the tools() method?

adrian-schnell commented 9 months ago

indeed the tool was missing as I understood it to either add it as tool or as link.

Now I added the tool as well. The link is still added manually. Sorry was a misunderstood of my side 🫣

But now I've a followup problem: The window remains empty except the navigations. In the console there's this error:

Bildschirmfoto 2023-11-10 um 09 20 09

In the class I copied the demo content:

<?php

namespace App\Nova\Wizard;

use Laravel\Nova\Fields;
use Wdelfuego\NovaWizard\AbstractWizard;

class CreateCommunityWizard extends AbstractWizard
{
    public function wizardViewData(): array
    {
        return [
            'steps' =>
                [
                    'title'  => 'Step 1/2',
                    'fields' => [
                        Fields\Text::make(__('Username'), 'username'),
                        Fields\Text::make(__('Text field'), 'myText'),
                        Fields\Textarea::make(__('Longer text'), 'myLongerText')
                            ->help("You can use Help texts on Nova fields like you're used to"),
                        Fields\Number::make(__('Some number'), 'myNumber')
                            ->rules('required')
                            ->withMeta(['value' => 60])
                            ->min(1)
                            ->step(1),
                    ],
                ],
            [
                'title'  => 'Step 2/2',
                'fields' => [
                    Fields\Text::make(__('Text field 2'), 'myText2'),
                    Fields\Textarea::make(__('Longer text 2'), 'myLongerText2')
                        ->help("You can use Help texts on Nova fields like you're used to"),
                    Fields\Number::make(__('Some number 2'), 'myNumber2')
                        ->rules('required')
                        ->withMeta(['value' => 60])
                        ->min(1)
                        ->step(1),
                ],
            ],
        ];
    }

    public function onSubmit($formData, &$context): bool
    {
        return true;
    }

    public function successViewData($context): array
    {
        return [
            'message' => 'Success! Your Community has been created.',
        ];
    }
}
wdelfuego commented 9 months ago

Thanks for letting me know. If you think the documentation can be improved, feel free to create a PR!

I've created a new issue for your Javascript error.