Currently I have a login, register, update and delete functionality using my api made in Laravel using passport feature. Everything works fine the insertion of data and fetc
This solution worked for me, found in the Laravel Docs. You can override the unauthenticated function in the Handler like this:
protected function unauthenticated($request, AuthenticationException $exception)
{
return $request->expectsJson()
? response()->json(['message' => $exception->getMessage()], 401)
: redirect()->guest(route('login'));
}
then, handle and provide the response you want.
Don't forget to import this as well in the Handle.php file:
use Illuminate\Auth\AuthenticationException;
I hope it does work well for you!