简体   繁体   中英

Laravel Nova Error 403 Page On Laravel Forge

I deployed my Laravel app with Laravel Nova on Laravel Forge. I installed Nova with a path repository, I have also Nova user. I replaced NovaServiceProvider Gate method like:

 Gate::define(‘viewNova’, function ($user) {

     return in_array($user->email, [

         ‘my@license.com’,

     ]);

 });

When I visiting page "/nova" there is login form but when I'm trying to log in with my existing user, it goes on 403 error page with the message “ Sorry, you are forbidden from accessing this page

The only article I found is " Common problems when setting up Laravel Nova " on Medium.

Problem #2 : there looks like my issue, but it's not. I think my issue is about the license, otherwise, I tried everything.

I have a solo Nova license and I have not to email support to ask them.

I have: Laravel 5.7 and Nova: 1.3.1

My question is: Should I buy the pro license? and why? Or what's the issue?

I believe your issue (unless it's not actually the code running), is due to the ' and ' characters surrounding the email address you're authorizing and what's being passed to define() . Try ' or " instead - PHP understands those, not the previous characters.

 Gate::define('viewNova', function ($user) {
     return in_array($user->email, [
         'my@license.com',
     ]);
 });

This is a common mistake if you're copying / pasting from text editors like Microsoft Word, or copying from online sources!

This often occurs if you have deployed to a production environment and haven't set up your Gate guard yet. Nova protects itself from being logged into when in the production environment. See this part of the documentation for how to clear that up:

https://nova.laravel.com/docs/1.0/installation.html#authorizing-nova

TL;DR - Add:

protected function gate()
{
    Gate::define('viewNova', function ($user) {
        return in_array($user->email, [
            'your@emails.com',
            'login@emails.com',
        ]);
    });
}

to app/Providers/NovaServiceProvider.php

Further to that - some housekeeping items to remember:

php artisan nova:install
php artisan key:generate
php artisan config:cache

After that you will have a new key in your environment file and your nova scaffolding will be installed, the configuration cache will be cleared too which can often cause bumps in the road.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM