Laravel

Laravel 5.7 Route [login] not defined

Since Laravel comes with Frontend Scaffolding and supports Vue within the box, therefore I decided to test Laravel 5.7 + Vue app running in same project.

I personally like keeping API/Micro service and App as two separate projects. But in certain situations using Laravel+Vue app in same project could be helpful.

While I was testing  API+Laravel Passport & Vue app, I  encountered an error “Route [login] not defined” when hitting any auth:api guarded endpoint without passing valid Bearer token.

Laravel introduced Authenticate middleware in version 5.7, that redirectes any unauthenticated request to login route by default.

Since I am using Laravel Passport, there I didn’t activated Auth::routes() in application, and for that obvious reason my app is missing web auth routes.

Authenticate middleware default behavior redirects the unauthenticated request to no existing /login route.

Requesting api auth guarded endpoint without valid token, throws InvalidArgumentException.

Middleware:

This error can be resolve by just commenting out.

// return route('login');

Author: Danyal
I'm a skilled programmer specializing in Vue.js/Nuxt.js for front-end development and PHP Laravel for back-end solutions. I have a strong focus on API design and development, complemented by experience in web server setup and maintenance. My versatile expertise ensures seamless creation and maintenance of web applications, covering everything from intuitive user interfaces to robust server-side functionality. Passionate about coding and driven by a lifelong learning mindset, I invite you to explore more at danyal.dk.