4

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?

Kenny Horna
  • 13,485
  • 4
  • 44
  • 71
  • Are you sure that the user exists in your database? Try to access your server thorugh SSH and check it in tinker. Btw, also check that your password is hashed. – Kenny Horna Feb 20 '19 at 16:13
  • Btwm don't think the problem is your license. The package is a bunch of php classes, if you installed your dependencies and the code is downloaded then you are good to go. – Kenny Horna Feb 20 '19 at 16:14

2 Answers2

9

This often occurs if you have deployed to a production environment and haven't set up your Gate guard yet. Or have a cached config, or are signed in as an email that isn’t whitelisted.

Ensure you add your emails like so:

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 optimize:clear

Clearing [config] caches can usually clear up bumps along the road.

Grant
  • 5,709
  • 2
  • 38
  • 50
1

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!

1000Nettles
  • 2,314
  • 3
  • 22
  • 31
  • Thanx, I have no idea why are incorrect symbols in my question, but I have correct symbols in my code. Updated info about my issue is that when I'm defining my environment as local, it's working good, otherwise there is same. So I'm sure it's a license issue. – Aleqsandre Shubitidze Feb 21 '19 at 14:16