sfelix-martins / passport-multiauth

Add support to multi-authentication to Laravel Passport
MIT License
288 stars 51 forks source link

Error "Route [login] not defined" #129

Open Aontaigh opened 4 years ago

Aontaigh commented 4 years ago

Laravel Version: 5.8 Multiauth Version: 5

I get the error as mentioned above when attempting to hit a protected route when not logged in and authenticated.

For example, imagine one is not logged in and attempts to hit the route customers:

Route::group(['prefix' => 'v1/osf', 'middleware' => ['multiauth:customer,api']], function () {
    Route::get('customers', 'OpenShopFront\Customers\CustomerControllerr@index');
    Route::get('customer/{id}', 'OpenShopFront\Customers\CustomerControllerr@show');
});

This will cause a 500 error stating "Error "Route [login] not defined".

I know when using passport you can use the Authenticate.php middleware and do something along the lines of:

<?php

namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;

class Authenticate extends Middleware {
    protected function redirectTo($request) {
        abort(response()->json([
            'status' => 'error',
            'message_short' => 'Not Authenticated - Please Login',
            'message_long' => null,
            'validation_error' => null
        ], 401));
    }
}

How would something such as the above be achieved?