Snippets

Why ActingAs Not working in Laravel API Testing

Hey,

You may come across this post because of your actingAs() is not working with Laravel API Testing. I discovered the error of why it was happening with me also.

In my case, I use a custom guard called jwt that was not using laravel actingAs() by default. That's why I always get 401 error, probably you too.

To address this issue, you need to pass the custom guard name, in my case, it was jwt.

$this->actingAs($user, 'jwt')->assetSuccess();

Hope it will work for you. :)