Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuthenticationException #11

Open
andersespedalen opened this issue Nov 13, 2020 · 3 comments
Open

AuthenticationException #11

andersespedalen opened this issue Nov 13, 2020 · 3 comments

Comments

@andersespedalen
Copy link

andersespedalen commented Nov 13, 2020

In the browser, login works fine using the same user as in the test
Regardless of using the seeded data, or creating the user in the test, I'm getting Unauthenticated when testing Index

test

public function admin_user_can_access_nova()
    {
        $this->be(User::create([
            'name' => 'admin',
            'email' => '[email protected]',
            'password' => bcrypt('Test1234'),
        ]));

        $response = $this->novaIndex('users');
        $response->assertOk();
        $response->assertCanView();
        $response->assertCanCreate();
        $response->assertCanUpdate();
        $response->assertCanDelete();
        $response->assertCanForceDelete();
        $response->assertCanRestore();
    }

In NovaServiceProvider, even I allow all users to debug

    protected function gate()
    {
        Gate::define('viewNova', function ($user) {
            return true;
        });
    }

PHPUnit

There was 1 error:
1) Tests\Feature\NovaTest::admin_user_can_access_nova
Laravel\Nova\Exceptions\AuthenticationException: Unauthenticated.

Environment:

Homestead 10
Laravel 7
Nova 3.14
@andersespedalen andersespedalen changed the title Unauthenticated Exception AuthenticationException Nov 13, 2020
@dillingham
Copy link
Owner

@andersespedalen hmmm I'll have to check with this specific version of nova maybe

Current version works for me

@brunocfalcao
Copy link

Hi @andersespedalen ,

I think you need to pass the default argument value to null in your define method.

Not ($user) but ($user = null).

As this:

protected function gate()
    {
        Gate::define('viewNova', function ($user = null) {
            return true;
        });
    }

@andersespedalen
Copy link
Author

Don't think so. The callback of Gate::define() does not require a default value.
At least not according to the Laravel documentation or the rest of my project. And adding it does not fix the problem.

This was referenced Apr 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants