Laravel Passport Route [login] not defined

Did you enter above-mentioned URL directly in browser search bar? If you did its wrong way because you also need to enter API token with your request__!!

To check either request includes token or not make your own middleware.

Command to create Middleware

php artisan make:middleware CheckApiToken

https://laravel.com/docs/5.6/middleware

change middleware handle method to

public function handle($request, Closure $next)
{
    if(!empty(trim($request->input('api_token')))){

        $is_exists = User::where('id' , Auth::guard('api')->id())->exists();
        if($is_exists){
            return $next($request);
        }
    }
        return response()->json('Invalid Token', 401);
}

Like This Your Url should be like this

http://localhost:8000/api/todos?api_token=API_TOKEN_HERE


You also have to add another header Key: Accept and value: application/json


Use Postman and set the Header Accept: application/json otherwise Laravel Passport would never know it's an API client and thus redirect to a /login page for the web.

see below image to see where to set the accept parameter: enter image description here


Check Your Header Request to put

Authorization = Bearer {your token}